-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "Basics_Utils.hxx"
#include "MEDLoader.hxx"
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
#include <string>
#include <vector>
_meshLastId = 0;
_fieldseriesLastId = 0;
}
+
MEDDataManager_i::~MEDDataManager_i()
{
LOG("Deleting MEDDataManager_i instance");
}
+void MEDDataManager_i::cleanUp()
+{
+ _fieldLastId = 0;
+ _sourceLastId = 0;
+ _meshLastId = 0;
+ _fieldseriesLastId = 0;
+
+ // [ABN] Is it the proper way?
+ _datasourceHandlerMap.clear();
+ _meshHandlerMap.clear();
+ _fieldseriesHandlerMap.clear();
+ _fieldHandlerMap.clear();
+ _fieldDoubleMap.clear();
+ _meshMap.clear();
+ _fieldPersistencyMap.clear();
+}
+
+
std::string MEDDataManager_i::file_to_source(const char * filepath)
{
string source("file://");
/*!
* This function loads the meta-data from the specified med file and
* returns the associated datasource handler. The data source handler
- * is a key to retrieve all informations concerning the data (meshes,
+ * is a key to retrieve all information concerning the data (meshes,
* fields).
*/
MEDCALC::DatasourceHandler * MEDDataManager_i::loadDatasource(const char *filepath) {
// We first check that this datasource is not already registered
long sourceid = getDatasourceId(filepath);
if ( sourceid != LONG_UNDEFINED ) {
- // The file is already registered under the identifier sourceid
- LOG("WRN: The file "<<filepath<<" is already registered with id="<<ToString(sourceid));
- return new MEDCALC::DatasourceHandler(*_datasourceHandlerMap[sourceid]);
+ // The file is already registered under the identifier sourceid
+ LOG("WRN: The file "<<filepath<<" is already registered with id="<<ToString(sourceid));
+ return new MEDCALC::DatasourceHandler(*_datasourceHandlerMap[sourceid]);
}
// Then we check that the file is readable by MEDLoader
- MEDLoader::CheckFileForRead(filepath);
+ CheckFileForRead(filepath);
// Initialise the datasource handler
MEDCALC::DatasourceHandler * datasourceHandler = new MEDCALC::DatasourceHandler();
_datasourceHandlerMap[datasourceHandler->id] = datasourceHandler;
// We start by read the list of meshes (spatial supports of fields)
- vector<string> meshNames = MEDLoader::GetMeshNames(filepath);
+ vector<string> meshNames = GetMeshNames(filepath);
int nbOfMeshes = meshNames.size();
for (int iMesh = 0; iMesh < nbOfMeshes; iMesh++) {
- const char * meshName = meshNames[iMesh].c_str();
- LOG("name of mesh " << iMesh << " = " << meshName);
-
- MEDCALC::MeshHandler * meshHandler = new MEDCALC::MeshHandler();
- meshHandler->id = _meshLastId; _meshLastId++;
- meshHandler->name = meshName;
- meshHandler->sourceid = datasourceHandler->id;
-
- _meshHandlerMap[meshHandler->id] = meshHandler;
-
- // For each mesh, we can read the list of the names of the
- // associated fields, i.e. fields whose spatial support is this
- // mesh.
- vector<string> fieldNames = MEDLoader::GetAllFieldNamesOnMesh(filepath,
- meshName);
- int nbOfFields = fieldNames.size();
- for (int iField = 0; iField < nbOfFields; iField++) {
- const char * fieldName = fieldNames[iField].c_str();
- LOG("-- name of field " << iField << " = " << fieldName);
-
- // A field name could identify several MEDCoupling fields, that
- // differ by their spatial discretization on the mesh (values on
- // cells, values on nodes, ...). This spatial discretization is
- // specified by the TypeOfField that is an integer value in this
- // list:
- // 0 = ON_CELLS
- // 1 = ON_NODES
- // 2 = ON_GAUSS_PT
- // 3 = ON_GAUSS_NE
-
- // As a consequence, before loading values of a field, we have
- // to determine the types of spatial discretization defined for
- // this field and to chooose one.
-
- vector<TypeOfField> listOfTypes = MEDLoader::GetTypesOfField(filepath,
- meshName,
- fieldName);
- int nbOfTypes = listOfTypes.size();
- for (int iType = 0; iType < nbOfTypes; iType++) {
- LOG("---- type "<<iType<<" of field "<<iField<< " = " << listOfTypes[iType]);
-
- // Then, we can get the iterations associated to this field on
- // this type of spatial discretization:
- std::vector< std::pair<int,int> > fieldIterations =
- MEDLoader::GetFieldIterations(listOfTypes[iType],
- filepath,
- meshName,
- fieldName);
-
- int nbFieldIterations = fieldIterations.size();
- LOG("---- nb. iterations = " << nbFieldIterations);
-
- // We can define the timeseries of fields (fieldseries) for
- // this type. A fieldseries is a macro object that handle the whole
- // set of time iterations of a field.
- MEDCALC::FieldseriesHandler * fieldseriesHandler = new MEDCALC::FieldseriesHandler();
- fieldseriesHandler->id = _fieldseriesLastId; _fieldseriesLastId++;
- fieldseriesHandler->name = fieldName;
- fieldseriesHandler->type = listOfTypes[iType];
- fieldseriesHandler->meshid = meshHandler->id;
- fieldseriesHandler->nbIter = nbFieldIterations;
- _fieldseriesHandlerMap[fieldseriesHandler->id] = fieldseriesHandler;
-
- // We can then load meta-data concerning all iterations
- for (int iterationIdx=0; iterationIdx<nbFieldIterations; iterationIdx++) {
-
- int iteration = fieldIterations[iterationIdx].first;
- int order = fieldIterations[iterationIdx].second;
-
- const char * source = datasourceHandler->uri;
- MEDCALC::FieldHandler * fieldHandler = newFieldHandler(fieldName,
- meshName,
- listOfTypes[iType],
- iteration,
- order,
- source);
-
- fieldHandler->meshid = meshHandler->id;
- fieldHandler->fieldseriesId = fieldseriesHandler->id;
- _fieldHandlerMap[fieldHandler->id] = fieldHandler;
- }
+ const char * meshName = meshNames[iMesh].c_str();
+ LOG("name of mesh " << iMesh << " = " << meshName);
+
+ MEDCALC::MeshHandler * meshHandler = new MEDCALC::MeshHandler();
+ meshHandler->id = _meshLastId; _meshLastId++;
+ meshHandler->name = meshName;
+ meshHandler->sourceid = datasourceHandler->id;
+
+ _meshHandlerMap[meshHandler->id] = meshHandler;
+
+ // For each mesh, we can read the list of the names of the
+ // associated fields, i.e. fields whose spatial support is this
+ // mesh.
+ vector<string> fieldNames = GetAllFieldNamesOnMesh(filepath,
+ meshName);
+ int nbOfFields = fieldNames.size();
+ for (int iField = 0; iField < nbOfFields; iField++) {
+ const char * fieldName = fieldNames[iField].c_str();
+ LOG("-- name of field " << iField << " = " << fieldName);
+
+ // A field name could identify several MEDCoupling fields, that
+ // differ by their spatial discretization on the mesh (values on
+ // cells, values on nodes, ...). This spatial discretization is
+ // specified by the TypeOfField that is an integer value in this
+ // list:
+ // 0 = ON_CELLS
+ // 1 = ON_NODES
+ // 2 = ON_GAUSS_PT
+ // 3 = ON_GAUSS_NE
+
+ // As a consequence, before loading values of a field, we have
+ // to determine the types of spatial discretization defined for
+ // this field and to choose one.
+
+ vector<TypeOfField> listOfTypes = GetTypesOfField(filepath,
+ meshName,
+ fieldName);
+ int nbOfTypes = listOfTypes.size();
+ for (int iType = 0; iType < nbOfTypes; iType++) {
+ LOG("---- type "<<iType<<" of field "<<iField<< " = " << listOfTypes[iType]);
+
+ // Then, we can get the iterations associated to this field on
+ // this type of spatial discretization:
+ std::vector< std::pair<int,int> > fieldIterations;
+
+ if (listOfTypes[iType] == MEDCoupling::ON_CELLS || listOfTypes[iType] == MEDCoupling::ON_NODES)
+ fieldIterations = GetFieldIterations(listOfTypes[iType],
+ filepath, meshName, fieldName);
+ else
+ {
+ LOG("---- WARNING - field " << fieldName << " is not on CELLS or on NODES");
+ typedef std::vector< std::pair< std::pair<int,int>, double> > TimeVec;
+ TimeVec fieldIterTime = GetAllFieldIterations(filepath, fieldName);
+ for (TimeVec::const_iterator it = fieldIterTime.begin(); it != fieldIterTime.end(); ++it)
+ fieldIterations.push_back(it->first);
+ }
+
+ int nbFieldIterations = fieldIterations.size();
+ LOG("---- nb. iterations = " << nbFieldIterations);
+
+ // We can define the timeseries of fields (fieldseries) for
+ // this type. A fieldseries is a macro object that handle the whole
+ // set of time iterations of a field.
+ MEDCALC::FieldseriesHandler * fieldseriesHandler = new MEDCALC::FieldseriesHandler();
+ fieldseriesHandler->id = _fieldseriesLastId; _fieldseriesLastId++;
+ fieldseriesHandler->name = fieldName;
+ fieldseriesHandler->type = listOfTypes[iType];
+ fieldseriesHandler->meshid = meshHandler->id;
+ fieldseriesHandler->nbIter = nbFieldIterations;
+ _fieldseriesHandlerMap[fieldseriesHandler->id] = fieldseriesHandler;
+
+ // We can then load meta-data concerning all iterations
+ for (int iterationIdx=0; iterationIdx<nbFieldIterations; iterationIdx++) {
+
+ int iteration = fieldIterations[iterationIdx].first;
+ int order = fieldIterations[iterationIdx].second;
+
+ const char * source = datasourceHandler->uri;
+ MEDCALC::FieldHandler * fieldHandler = newFieldHandler(fieldName,
+ meshName,
+ listOfTypes[iType],
+ iteration,
+ order,
+ source);
+
+ fieldHandler->meshid = meshHandler->id;
+ fieldHandler->fieldseriesId = fieldseriesHandler->id;
+ _fieldHandlerMap[fieldHandler->id] = fieldHandler;
+ // LOG("=== Storing " << fieldName << " (" << fieldHandler->id << ")");
+ }
+ }
}
- }
}
return new MEDCALC::DatasourceHandler(*datasourceHandler);
return NULL;
}
+MEDCALC::DatasourceHandler*
+MEDDataManager_i::getDatasourceHandlerFromID(CORBA::Long sourceid)
+{
+ DatasourceHandlerMapIterator it = _datasourceHandlerMap.find(sourceid);
+ if (it != _datasourceHandlerMap.end())
+ {
+ return it->second;
+ }
+ return NULL;
+}
-MEDCALC::MeshHandler * MEDDataManager_i::getMesh(CORBA::Long meshId) {
+MEDCALC::MeshHandler * MEDDataManager_i::getMeshHandler(CORBA::Long meshId) {
if ( _meshHandlerMap.count(meshId) == 0 ) {
std::string message =
std::string("The mesh of id=") + ToString(meshId) +
/*!
* This function returns the list of mesh handlers associated to the
- * specified datasource. It corresponds to the list ofmeshes defined
+ * specified datasource. It corresponds to the list of meshes defined
* in the datasource.
*/
-MEDCALC::MeshHandlerList * MEDDataManager_i::getMeshList(CORBA::Long datasourceId) {
+MEDCALC::MeshHandlerList * MEDDataManager_i::getMeshHandlerList(CORBA::Long datasourceId) {
- // We initiate a list with the maximum lentgh
+ // We initiate a list with the maximum length
MEDCALC::MeshHandlerList_var meshHandlerList = new MEDCALC::MeshHandlerList();
meshHandlerList->length(_meshHandlerMap.size());
* specified mesh.
*/
MEDCALC::FieldseriesHandlerList * MEDDataManager_i::getFieldseriesListOnMesh(CORBA::Long meshId) {
- // We initiate a list with the maximum lentgh
+ // We initiate a list with the maximum length
MEDCALC::FieldseriesHandlerList_var
fieldseriesHandlerList = new MEDCALC::FieldseriesHandlerList();
fieldseriesHandlerList->length(_fieldseriesHandlerMap.size());
*/
MEDCALC::FieldHandlerList * MEDDataManager_i::getFieldListInFieldseries(CORBA::Long fieldseriesId) {
- // We initiate a list with the maximum lentgh
+ // We initiate a list with the maximum length
MEDCALC::FieldHandlerList_var fieldHandlerList = new MEDCALC::FieldHandlerList();
fieldHandlerList->length(_fieldHandlerMap.size());
* This returns a copy of the fieldHandler associated to the specified id.
*/
MEDCALC::FieldHandler * MEDDataManager_i::getFieldHandler(CORBA::Long fieldHandlerId) {
- LOG("getFieldHandler: START")
+// LOG("getFieldHandler: START")
FieldHandlerMapIterator fieldIt = _fieldHandlerMap.find(fieldHandlerId);
if ( fieldIt != _fieldHandlerMap.end() ) {
// >>> WARNING: CORBA struct specification indicates that the
- // assignement acts as a desctructor for the structure that is
- // pointed to. The values of the fields are copy first in the new
- // structure that receives the assignement and finally the initial
+ // assignment acts as a destructor for the structure that its
+ // pointed to. The values of the fields are copied first in the new
+ // structure that receives the assignment and finally the initial
// structure is destroyed. In the present case, WE WANT to keep
// the initial fieldHandler in the map. We must then make a deep
// copy of the structure found in the map and return the copy. The
try {
bool writeFromScratch = true;
- MEDLoader::WriteField(filepath, fieldDouble, writeFromScratch);
+ WriteField(filepath, fieldDouble, writeFromScratch);
writeFromScratch = false;
for(CORBA::ULong i=1; i<fieldIdList.length(); i++) {
fieldHandlerId = fieldIdList[i];
fieldHandler = getFieldHandler(fieldHandlerId);
fieldDouble = getFieldDouble(fieldHandler);
- MEDLoader::WriteField(filepath, fieldDouble, writeFromScratch);
+ WriteField(filepath, fieldDouble, writeFromScratch);
}
}
catch (INTERP_KERNEL::Exception &ex) {
* function savePersistentFields is called.
*/
void MEDDataManager_i::markAsPersistent(CORBA::Long fieldHandlerId, bool persistent) {
- LOG("mark as persistant : id="<<fieldHandlerId);
+ LOG("mark as persistent : id="<<fieldHandlerId);
_fieldPersistencyMap[fieldHandlerId] = persistent;
}
std::string filepath(source_to_file((_datasourceHandlerMap[sourceid])->uri));
const char * meshName = _meshHandlerMap[meshHandlerId]->name;
int meshDimRelToMax = 0;
- myMesh = MEDLoader::ReadUMeshFromFile(filepath,meshName,meshDimRelToMax);
+ myMesh = ReadUMeshFromFile(filepath,meshName,meshDimRelToMax);
_meshMap[meshHandlerId] = myMesh;
}
return myMesh;
* i.e. the MEDCoupling field associated to the specified field
* handler. If the field source is a file and the data ar not loaded
* yet, the this function load the data from the file in a MEDCoupling
- * field instance. Otherwize, it just returns the MEDCoupling field
+ * field instance. Otherwise, it just returns the MEDCoupling field
* instance.
*/
MEDCouplingFieldDouble * MEDDataManager_i::getFieldDouble(const MEDCALC::FieldHandler * fieldHandler)
// one case where we can arrive here with no previous call to
// loadDataSource: for example the field handler list can be obtained
// from a call to addFieldsFromFile instead of loadDataSource (see
- // for exemple the getFieldRepresentation service of the
+ // for example the getFieldRepresentation service of the
// dataManager, that comes here and then calls getUMesh where we
// need a map initialized only in loadDataSource) <<<<
long meshid = fieldHandler->meshid;
LOG("getFieldDouble: field "<<fieldHandler->fieldname<<" loaded from file "<<filepath);
TypeOfField type = (TypeOfField)fieldHandler->type;
int meshDimRelToMax = 0;
- MEDCouplingFieldDouble * myField = MEDLoader::ReadField(type,
+ MCAuto<MEDCouplingField> myFieldTmpp(ReadField(type,
filepath,
meshName,
meshDimRelToMax,
std::string(fieldHandler->fieldname),
fieldHandler->iteration,
- fieldHandler->order);
+ fieldHandler->order));
+ MCAuto<MEDCouplingFieldDouble> myField(DynamicCast<MEDCouplingField,MEDCouplingFieldDouble>(myFieldTmpp));
myField->setMesh(myMesh);
- _fieldDoubleMap[fieldHandler->id] = myField;
+ _fieldDoubleMap[fieldHandler->id] = myField.retn();
return myField;
}
// WARN: note that the variables "iteration" and "order" are passed
// by reference to the function getTime (see documentation of
// MEDCouplingField). As a consequence, the values of these
- // variables are updated by this function call. This is the mean to
+ // variables are updated by this function call. This is the means to
// retrieve the iteration and order of the field.
double timestamp = fieldDouble->getTime(iteration, order);
source->c_str());
if ( meshHandlerId == LONG_UNDEFINED ) {
- // We have to gess the id of the underlying mesh to preserve data
+ // We have to guess the id of the underlying mesh to preserve data
// integrity (a fieldHandler must have an attribute that contains
// the id of its underlying mesh):
//
_fieldHandlerMap[fieldHandler->id] = fieldHandler;
_fieldDoubleMap[fieldHandler->id] = fieldDouble;
- // >>> WARNING: CORBA structure assignement specification ==> return
+ // >>> WARNING: CORBA structure assignment specification ==> return
// >>> a deep copy to avoid the destruction of the fieldHandler
- // >>> registered in the map (assignement acts as a destructor for
+ // >>> registered in the map (assignment acts as a destructor for
// >>> CORBA struct).
return new MEDCALC::FieldHandler(*fieldHandler);
}
throw KERNEL::createSalomeException(message.c_str());
}
-ParaMEDMEM::NatureOfField MEDDataManager_i::_getNatureOfField(const char* fieldNature) {
+MEDCoupling::NatureOfField MEDDataManager_i::_getNatureOfField(const char* fieldNature) {
std::string nature(fieldNature);
if (nature == "NoNature") {
return NoNature;
}
- else if (nature == "ConservativeVolumic") {
- return ConservativeVolumic;
+ else if (nature == "IntensiveMaximum") {
+ return IntensiveMaximum;
}
- else if (nature == "Integral") {
- return Integral;
+ else if (nature == "ExtensiveMaximum") {
+ return ExtensiveMaximum;
}
- else if (nature == "IntegralGlobConstraint") {
- return IntegralGlobConstraint;
+ else if (nature == "ExtensiveConservation") {
+ return ExtensiveConservation;
}
- else if (nature == "RevIntegral") {
- return RevIntegral;
+ else if (nature == "IntensiveConservation") {
+ return IntensiveConservation;
}
std::string message("Error when trying to interpolate field: ");
std::string method(params.method);
double defaultValue = params.defaultValue;
bool reverse = params.reverse;
- ParaMEDMEM::NatureOfField nature = this->_getNatureOfField(params.nature);
+ MEDCoupling::NatureOfField nature = this->_getNatureOfField(params.nature);
// 1. Build remapper between sourceMesh and targetMesh (compute interpolation matrix)
MEDCouplingRemapper remapper;