#include "Face.hxx"
#include "Field.hxx"
#include "MEDFileMesh.hxx"
+#include "MEDFileField1TS.hxx"
#include "MEDLoader.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
//----------------------------------------------------------------------
{
_field=NULL;
+ _ff=NULL;
_typeField=typeField;
_numberOfComponents=0;
}
Field::Field(const std::string fieldName, EntityType type, const Mesh& mesh, int numberOfComponents, double time)
{
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(mesh);
_typeField=type;
_numberOfComponents=numberOfComponents;
_field->setArray(array);
_field->setTime(_time,0,0);
array->decrRef();
- mu->decrRef();
}
Field::Field( const std::string filename, EntityType type,
const std::string & fieldName,
- int iteration, int order, int meshLevel,
- int numberOfComponents, double time)
+ int iteration, int order, int meshLevel)
{
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(filename + ".med", meshLevel);
_typeField=type;
- _numberOfComponents=numberOfComponents;
- _time=time;
_fieldName=fieldName;
readFieldMed(filename, type, fieldName, iteration, order);
const std::string & fieldName, int meshLevel, double time )
{
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(meshFileName + ".med", meshLevel);
_typeField=type;
_numberOfComponents=Vconstant.size();
for (int ielem=0 ; ielem<nbelem; ielem++)
for (int jcomp=0 ; jcomp<nbcomp ; jcomp++)
- _field->getArray()->getPointer()[jcomp+ielem*_field->getNumberOfComponents()]=Vconstant[jcomp];
+ _field->getArray()->getPointer()[jcomp+ielem*nbcomp]=Vconstant[jcomp];
}
Field::Field(const Mesh& M, EntityType type, const Vector Vconstant, const std::string & fieldName, double time)
{
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(M);
_typeField=type;
_numberOfComponents=Vconstant.size();
for (int ielem=0 ; ielem<nbelem; ielem++)
for (int jcomp=0 ; jcomp<nbcomp ; jcomp++)
- _field->getArray()->getPointer()[jcomp+ielem*_field->getNumberOfComponents()]=Vconstant[jcomp];
+ _field->getArray()->getPointer()[jcomp+ielem*nbcomp]=Vconstant[jcomp];
}
Field::Field(const Mesh& M, EntityType type, const vector<double> Vconstant, const std::string & fieldName, double time)
{
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(M);
_typeField=type;
_numberOfComponents=Vconstant.size();
for (int ielem=0 ; ielem<nbelem; ielem++)
for (int jcomp=0 ; jcomp<nbcomp ; jcomp++)
- _field->getArray()->getPointer()[jcomp+ielem*_field->getNumberOfComponents()]=Vconstant[jcomp];
+ _field->getArray()->getPointer()[jcomp+ielem*nbcomp]=Vconstant[jcomp];
}
Field::Field( int nDim, const vector<double> Vconstant, EntityType type,
double xmin, double xmax, int nx, string leftSide, string rightSide,
const std::string & fieldName, double time,double epsilon)
{
_field = NULL;
+ _ff=NULL;
_typeField=type;
_numberOfComponents=Vconstant.size();
_time=time;
for (int ielem=0 ; ielem<nbelem; ielem++)
for (int jcomp=0 ; jcomp<nbcomp ; jcomp++)
- _field->getArray()->getPointer()[jcomp+ielem*_field->getNumberOfComponents()]=Vconstant[jcomp];
+ _field->getArray()->getPointer()[jcomp+ielem*nbcomp]=Vconstant[jcomp];
}
Field::Field(const Mesh M, const Vector VV_Left, const Vector VV_Right, double disc_pos,
EntityType type, int direction, const std::string & fieldName, double time)
throw CdmathException( "Field::Field: Vectors VV_Left and VV_Right have different sizes");
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(M);
_typeField=type;
_numberOfComponents=VV_Left.getNumberOfRows();
for (int i=0; i< nbcomp; i++)
if (component_value< disc_pos )
- _field->getArray()->getPointer()[j+i*_field->getNumberOfComponents()] = VV_Left[i];
+ _field->getArray()->getPointer()[j+i*nbcomp] = VV_Left[i];
else
- _field->getArray()->getPointer()[j+i*_field->getNumberOfComponents()] = VV_Right[i];
+ _field->getArray()->getPointer()[j+i*nbcomp] = VV_Right[i];
}
}
Field::Field( int nDim, const vector<double> VV_Left, vector<double> VV_Right,
}
_field = NULL;
+ _ff=NULL;
_mesh=Mesh(M);
_typeField=type;
_numberOfComponents=Vout.size();
}
if((currentPoint-Center).norm()<radius)
for(int j=0;j<nbcomp;j++)
- _field->getArray()->getPointer()[j+i*_field->getNumberOfComponents()]=Vin[j];
+ _field->getArray()->getPointer()[j+i*nbcomp]=Vin[j];
else
for(int j=0;j<nbcomp;j++)
- _field->getArray()->getPointer()[j+i*_field->getNumberOfComponents()]=Vout[j];
+ _field->getArray()->getPointer()[j+i*nbcomp]=Vout[j];
}
}
size_t iField = 0;
std::string attributedFieldName;
_field = NULL;
+ _ff=NULL;
// Get the name of the right field that we will attribute to the Field.
if (fieldName == "") {
if (fieldNames.size() > 0)
+ {
+ cout<<"Warning : No field name imposed, taking the first field name found : "<< fieldNames[0]<<" in file "<<completeFileName<<endl;;
attributedFieldName = fieldNames[0];
- else {
+ }
+ else
+ {
std::ostringstream message;
- message << "No field in file " << completeFileName;
+ message << "Warning : No field found in file " << completeFileName;
throw CdmathException(message.str().c_str());
}
}
- else {
- for (; iField < fieldNames.size(); iField++)
- if (fieldName == fieldNames[iField]) break;
-
- if (iField < fieldNames.size())
+ else
+ {
+ int mycount = std::count(fieldNames.begin(), fieldNames.end(), fieldName);
+
+ if( mycount>0 )
+ {
attributedFieldName = fieldName;
+
+ if( mycount> 1 )
+ cout<<"Warning : " << mycount << " fields are associated to the name " << fieldName <<" in file "<<completeFileName<<endl;
+ }
else {
std::ostringstream message;
message << "No field named " << fieldName << " in file " << completeFileName;
}
// Get the name of the right mesh that we will attribute to the Field.
- std::vector<std::string> meshNames
- = MEDCoupling::GetMeshNamesOnField(completeFileName, attributedFieldName);
+ std::vector<std::string> meshNames = MEDCoupling::GetMeshNamesOnField(completeFileName, attributedFieldName);
if (meshNames.size() == 0) {
std::ostringstream message;
- message << "No mesh associated to " << fieldName
- << " in file " << completeFileName;
+ message << "No mesh associated to " << fieldName<< " in file " << completeFileName;
throw CdmathException(message.str().c_str());
}
+ else
+ if( meshNames.size() > 1 )
+ {
+ cout<<"Warning : " << meshNames.size() << " meshes are associated to field named " << fieldName <<" in file "<<completeFileName<<endl;
+ cout<<"Mesh names are : ";
+ for (int iMesh=0; iMesh < meshNames.size(); iMesh++)
+ cout<< meshNames[iMesh]<<", ";
+ cout<<endl<<"Taking the mesh with name "<< meshNames[0]<<endl;
+ }
+
std::string attributedMeshName = meshNames[0];
// Create Field.
- MEDCoupling::TypeOfField medFieldType[3] = { ON_CELLS, ON_NODES, ON_CELLS };
- switch (type) {
- case CELLS:
- _field = dynamic_cast< MEDCoupling::MEDCouplingFieldDouble * > (
- MEDCoupling::ReadFieldCell( completeFileName,
- attributedMeshName, 0,
- attributedFieldName, iteration, order) );
- break;
- case NODES:
- _field = dynamic_cast< MEDCoupling::MEDCouplingFieldDouble * > (
- MEDCoupling::ReadFieldNode( completeFileName,
- attributedMeshName, 0,
- attributedFieldName, iteration, order) );
- break;
- case FACES:
- _field = dynamic_cast< MEDCoupling::MEDCouplingFieldDouble * > (
- MEDCoupling::ReadFieldCell( completeFileName,
- attributedMeshName, -1,
- attributedFieldName, iteration, order) );
- break;
+ switch (type)
+ {
+ case CELLS:
+ _field = dynamic_cast< MEDCoupling::MEDCouplingFieldDouble * > (
+ MEDCoupling::ReadFieldCell( completeFileName,
+ attributedMeshName, 0,
+ attributedFieldName, iteration, order) );
+ break;
+ case NODES:
+ _field = dynamic_cast< MEDCoupling::MEDCouplingFieldDouble * > (
+ MEDCoupling::ReadFieldNode( completeFileName,
+ attributedMeshName, 0,
+ attributedFieldName, iteration, order) );
+ break;
+ case FACES:
+ _field = dynamic_cast< MEDCoupling::MEDCouplingFieldDouble * > (
+ MEDCoupling::ReadFieldCell( completeFileName,
+ attributedMeshName, -1,
+ attributedFieldName, iteration, order) );
+ break;
}
+
+ //Read and store the number of components
+ _numberOfComponents = _field->getNumberOfComponents() ;
+ _time = _field->getTime(iteration, order);
+
+ cout<<"Found field " << fieldName << " in file " << completeFileName <<endl;
}
int nbElem=f.getNumberOfElements();
for (int ielem=0 ; ielem<nbElem; ielem++)
for (int jcomp=0 ; jcomp<nbComp ; jcomp++)
- fres(ielem, jcomp)=_field->getArray()->getConstPointer()[jcomp+ielem*_field->getNumberOfComponents()]+f(ielem, jcomp);
+ fres(ielem, jcomp)=_field->getArray()->getConstPointer()[jcomp+ielem*nbComp]+f(ielem, jcomp);
return fres;
}
int nbElem=f.getNumberOfElements();
for (int ielem=0 ; ielem<nbElem; ielem++)
for (int jcomp=0 ; jcomp<nbComp ; jcomp++)
- fres(ielem, jcomp)=_field->getArray()->getConstPointer()[jcomp+ielem*_field->getNumberOfComponents()]-f(ielem, jcomp);
+ fres(ielem, jcomp)=_field->getArray()->getConstPointer()[jcomp+ielem*nbComp]-f(ielem, jcomp);
return fres;
}
int nbElem=getNumberOfElements();
for (int i=0 ; i<nbComp ; i++)
for (int j=0 ; j<nbElem; j++)
- _field->getArray()->getPointer()[i+j*_field->getNumberOfComponents()]*=s;
+ _field->getArray()->getPointer()[i+j*nbComp]*=s;
return *this;
}
int nbElem=getNumberOfElements();
for (int i=0 ; i<nbComp ; i++)
for (int j=0 ; j<nbElem; j++)
- _field->getArray()->getPointer()[i+j*_field->getNumberOfComponents()]/=s;
+ _field->getArray()->getPointer()[i+j*nbComp]/=s;
return *this;
}
int nbElem=getNumberOfElements();
for (int i=0 ; i<nbComp ; i++)
for (int j=0 ; j<nbElem; j++)
- _field->getArray()->getPointer()[i+j*_field->getNumberOfComponents()]-=s;
+ _field->getArray()->getPointer()[i+j*nbComp]-=s;
return *this;
}
int nbElem=getNumberOfElements();
for (int i=0 ; i<nbComp ; i++)
for (int j=0 ; j<nbElem; j++)
- _field->getArray()->getPointer()[i+j*_field->getNumberOfComponents()]+=s;
+ _field->getArray()->getPointer()[i+j*nbComp]+=s;
return *this;
}
Field::writeVTK (std::string fileName, bool fromScratch) const
//----------------------------------------------------------------------
{
+ if( !_mesh.isStructured() && !_mesh.meshNotDeleted() )
+ throw CdmathException("Field::writeVTK : Cannot save field in VTK format : unstructured mesh with no MEDCouplingUMesh loaded. Use med format.");
+
string fname=fileName+".pvd";
int iter,order;
double time=_field->getTime(iter,order);
//----------------------------------------------------------------------
{
string fname=fileName+".med";
- if (fromScratch)
- MEDCoupling::WriteField(fname.c_str(),_field,fromScratch);
- else
- MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(fname.c_str(),_field);
+
+ if(_mesh.isStructured() || _mesh.meshNotDeleted())
+ if (fromScratch)
+ MEDCoupling::WriteField(fname.c_str(),_field,fromScratch);
+ else
+ MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(fname.c_str(),_field);
+ else//The mesh has ben deleted, use _ff instead of _field to save the values
+ {
+ //MEDFileUMesh * meshMEDFile = MEDFileUMesh::New();
+ //meshMEDFile->setMeshAtLevel(0,_field->getMesh()->buildUnstructured());
+ //meshMEDFile->write(fname.c_str(), fromScratch);
+ //MEDCoupling::WriteUMesh(fname.c_str(),_field->getMesh()->buildUnstructured(),fromScratch);
+ //MEDCoupling::WriteMesh(fname.c_str(),_field->getMesh(),fromScratch);
+ //MEDCoupling::MEDCouplingUMesh* fmesh = dynamic_cast<MEDCoupling::MEDCouplingUMesh*> (_field->getMesh()->deepCopy());
+ //cout<<" checkConsecutiveCellTypes : "<< fmesh->checkConsecutiveCellTypes() <<endl;
+ //cout<<" advancedRepr() : "<< fmesh->advancedRepr() <<endl;
+ //cout<<" checkConsecutiveCellTypes : "<< _field->getMesh()->buildUnstructured()->checkConsecutiveCellTypes()<<endl;
+ MEDFileField1TS *ff=MEDFileField1TS::New();
+ _ff->setFieldNoProfileSBT( _field );
+ _ff->write(fname.c_str(), fromScratch);
+ }
}
Field
out<< field.getField().retn()->getArray()->repr();
return out;
}
+
+void Field::deleteMEDCouplingUMesh()
+{
+ return _mesh.deleteMEDCouplingUMesh();
+}