// 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
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 = 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 = 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 =
- 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;
-// LOG("=== Storing " << fieldName << " (" << fieldHandler->id << ")");
- }
+ 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 chooose 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);
_fileName = dataSHandler->uri;
_fieldName = fieldHandler->fieldname;
- _fieldType = getFieldTypeString((MEDCoupling::TypeOfField) fieldHandler->type);
+ _mcFieldType = (MEDCoupling::TypeOfField) fieldHandler->type;
+ _pvFieldType = getPVFieldTypeString(_mcFieldType);
_meshName = meshHandler->name;
if (_fileName.substr(0, 7) != std::string("file://")) {
MEDPresentation::execPyLine(const std::string & lin)
{
MEDPyLockWrapper lock;
- STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
+// STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
if(PyRun_SimpleString(lin.c_str()))
{
std::ostringstream oss;
{
MEDPyLockWrapper lock;
pushAndExecPyLine( "import pvsimple as pvs;");
+ pushAndExecPyLine( "import medcalc");
}
}
std::string
-MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const
+MEDPresentation::getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const
{
switch(fieldType)
{
return "CELLS";
case MEDCoupling::ON_NODES:
return "POINTS";
+ case MEDCoupling::ON_GAUSS_PT:
+ return "POINTS"; // because internally after application of the ELGA filter, the field will appear as a POINT field
default:
- STDLOG("MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?");
+ STDLOG("MEDPresentation::getPVFieldTypeString() -- Not implemented ! ELNO field?");
return "";
}
}
return oss.str();
}
+/*!
+ * Creates the MEDReader source in the pipeline, and potentially apply GAUSS/ELNO filters.
+ */
void
MEDPresentation::createSource()
{
+ std::string typ;
+ switch(_mcFieldType) {
+ case MEDCoupling::ON_CELLS: typ = "P0"; break;
+ case MEDCoupling::ON_NODES: typ = "P1"; break;
+ case MEDCoupling::ON_GAUSS_PT: typ = "GAUSS"; break;
+ default:
+ const char * msg ="MEDPresentation::createSource(): field type not impl. yet!";
+ STDLOG(msg);
+ throw KERNEL::createSalomeException(msg);
+ }
+
std::ostringstream oss;
oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "medcalc.SelectSourceField(" << _srcObjVar << ", '" << _meshName << "', '"
+ << _fieldName << "', '" << typ << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
oss << _srcObjVar << ".GenerateVectors = 1;";
pushAndExecPyLine(oss.str()); oss.str("");
+
+ // Deal with GAUSS fields:
+ if(_mcFieldType == MEDCoupling::ON_GAUSS_PT)
+ {
+ std::ostringstream oss, oss2;
+ oss2 << "__srcObj" << GeneratePythonId();
+ oss << oss2.str() << " = pvs.GaussPoints(Input=" << _srcObjVar << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ // Now the source becomes the result of the CellDatatoPointData:
+ _srcObjVar = oss2.str();
+ oss << _srcObjVar << ".SelectSourceArray = ['CELLS', 'ELGA@0'];";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ }
+ if(_mcFieldType == MEDCoupling::ON_GAUSS_NE)
+ {
+ const char * msg ="MEDPresentation::createSource(): ELNO field never tested!";
+ STDLOG(msg);
+ throw KERNEL::createSalomeException(msg);
+
+ std::ostringstream oss, oss2;
+ oss2 << "__srcObj" << GeneratePythonId();
+ oss << oss2.str() << " = pvs.ELNOMesh(Input=" << _srcObjVar << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ // Now the source becomes the result of the CellDatatoPointData:
+ _srcObjVar = oss2.str();
+// oss << _srcObjVar << ".SelectSourceArray = ['CELLS', 'ELNO@0'];";
+// pushAndExecPyLine(oss.str()); oss.str("");
+ }
}
void
MEDPyLockWrapper lock; // GIL!
std::string typ;
- if(_fieldType == "CELLS") {
+ if(_pvFieldType == "CELLS") {
typ = "CellData";
}
- else if (_fieldType == "POINTS") {
+ else if (_pvFieldType == "POINTS") {
typ = "PointData";
}
else {
- std::string msg("Unsupported spatial discretisation: " + _fieldType);
+ std::string msg("Unsupported spatial discretisation: " + _pvFieldType);
STDLOG(msg);
throw KERNEL::createSalomeException(msg.c_str());
}
void
MEDPresentation::applyCellToPointIfNeeded()
{
- std::ostringstream oss, oss2;
- // Apply Cell data to point data:
- oss2 << "__srcObj" << GeneratePythonId();
- oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
- pushAndExecPyLine(oss.str()); oss.str("");
- // Now the source becomes the result of the CellDatatoPointData:
- _srcObjVar = oss2.str();
-}
-
-/**
- * Convert a vector field into a 3D vector field:
- * - if the vector field is already 3D, nothing to do
- * - if it is 2D, then add a null component
- * - otherwise (tensor field, scalar field) throw
- */
-void
-MEDPresentation::convertTo3DVectorField()
-{
- std::ostringstream oss, oss1, oss2, oss3;
-
- int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
- if (nbCompo < 2 || nbCompo > 3)
- {
- oss << "The field '" << _fieldName << "' must have 2 or 3 components for this presentation!";
- STDLOG(oss.str());
- throw KERNEL::createSalomeException(oss.str().c_str());
- }
- if (nbCompo == 3)
- return;
-
- // Apply calculator:
- oss2 << "__srcObj" << GeneratePythonId();
- oss << oss2.str() << " = pvs.Calculator(Input=" << _srcObjVar << ");";
- pushAndExecPyLine(oss.str()); oss.str("");
- // Now the source becomes the result of the CellDatatoPointData:
- _srcObjVar = oss2.str();
- std::string typ;
- if(_fieldType == "CELLS")
- typ = "Cell Data";
- else if(_fieldType == "POINTS")
- typ = "Point Data";
- else
+ if (_pvFieldType == "CELLS")
{
- oss3 << "Field '" << _fieldName << "' has invalid field type";
- STDLOG(oss3.str());
- throw KERNEL::createSalomeException(oss3.str().c_str());
+ std::ostringstream oss, oss2;
+ // Apply Cell data to point data:
+ oss2 << "__srcObj" << GeneratePythonId();
+ oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ // Now the source becomes the result of the CellDatatoPointData:
+ _srcObjVar = oss2.str();
}
- oss << _srcObjVar << ".AttributeMode = '" << typ << "';";
- pushAndExecPyLine(oss.str()); oss.str("");
- oss << _srcObjVar << ".ResultArrayName = '" << _fieldName << "_CALC';"; // will never be needed I think
- pushAndExecPyLine(oss.str()); oss.str("");
- oss << _srcObjVar << ".Function = '" << _fieldName << "_0*iHat + " << _fieldName << "_1*jHat + 0.0*zHat';";
- pushAndExecPyLine(oss.str()); oss.str("");
}
-//double
-//MEDPresentation::computeCellAverageSize()
+///**
+// * Convert a vector field into a 3D vector field:
+// * - if the vector field is already 3D, nothing to do
+// * - if it is 2D, then add a null component
+// * - otherwise (tensor field, scalar field) throw
+// */
+//void
+//MEDPresentation::convertTo3DVectorField()
//{
-// std::ostringstream oss;
-// oss << "import MEDLoader;";
-// pushAndExecPyLine(oss.str()); oss.str("");
-// oss << "__mesh = MEDLoader.ReadMeshFromFile('" << _fileName << "', '" << _meshName << "');";
-// pushAndExecPyLine(oss.str()); oss.str("");
+// std::ostringstream oss, oss1, oss2, oss3;
//
-// oss << "__bb = __mesh.getBoundingBox()";
+// int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
+// if (nbCompo < 2 || nbCompo > 3)
+// {
+// oss << "The field '" << _fieldName << "' must have 2 or 3 components for this presentation!";
+// STDLOG(oss.str());
+// throw KERNEL::createSalomeException(oss.str().c_str());
+// }
+// if (nbCompo == 3)
+// return;
+//
+// // Apply calculator:
+// oss2 << "__srcObj" << GeneratePythonId();
+// oss << oss2.str() << " = pvs.Calculator(Input=" << _srcObjVar << ");";
// pushAndExecPyLine(oss.str()); oss.str("");
-// oss << "__deltas = [x[1]-x[0] for x in __bb];";
+// // Now the source becomes the result of the CellDatatoPointData:
+// _srcObjVar = oss2.str();
+// std::string typ;
+// if(_pvFieldType == "CELLS")
+// typ = "Cell Data";
+// else if(_pvFieldType == "POINTS")
+// typ = "Point Data";
+// else
+// {
+// oss3 << "Field '" << _fieldName << "' has invalid field type";
+// STDLOG(oss3.str());
+// throw KERNEL::createSalomeException(oss3.str().c_str());
+// }
+// oss << _srcObjVar << ".AttributeMode = '" << typ << "';";
// pushAndExecPyLine(oss.str()); oss.str("");
-// oss << "__vol = reduce(lambda x,y:x*y, __deltas, 1.0);";
+// oss << _srcObjVar << ".ResultArrayName = '" << _fieldName << "_CALC';"; // will never be needed I think
// pushAndExecPyLine(oss.str()); oss.str("");
-// // Average cell size is the the n-th root of average volume of a cell, with n being the space dimension
-// oss << "__cellSize = (__vol/__mesh.getNumberOfCells())**(1.0/len(__bb));";
+// oss << _srcObjVar << ".Function = '" << _fieldName << "_0*iHat + " << _fieldName << "_1*jHat + 0.0*zHat';";
// pushAndExecPyLine(oss.str()); oss.str("");
-//
-// PyObject * pyObj = getPythonObjectFromMain("__cellSize");
-// bool err = false;
-// if (!pyObj || !PyFloat_Check(pyObj)) { /* nothing to do, err handler below */}
-// else {
-// double ret= PyFloat_AsDouble(pyObj);
-// if(!PyErr_Occurred())
-// return ret;
-// }
-// // From here, an error for sure.
-// const char * msg = "MEDPresentation::computeCellAverageSize(): Python error.";
-// STDLOG(msg);
-// throw KERNEL::createSalomeException(msg);
//}
+
virtual void internalGeneratePipeline();
PyObject* getPythonObjectFromMain(const char* var) const;
-// void pushPyObjects(PyObjectId obj, PyObjectId disp);
void execPyLine(const std::string & lin);
void pushAndExecPyLine(const std::string & lin);
void fillAvailableFieldComponents();
void applyCellToPointIfNeeded();
- void convertTo3DVectorField();
-// double computeCellAverageSize();
- //void computeFieldRange
+// void convertTo3DVectorField();
// virtual MEDCALC::ViewModeType getViewMode() = 0;
void setParameters(const PresentationParameters& params);
private:
- std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
+ std::string getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
// The following functions are reserved to friend class MEDPresentationManager
void generatePipeline();
std::string _meshName;
std::string _fileName;
std::string _fieldName;
- std::string _fieldType;
+
+ ///! MEDCoupling field type (ON_NODES, ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE
+ MEDCoupling::TypeOfField _mcFieldType;
+ ///! ParaView field type: "CELLS" or "POINTS"
+ std::string _pvFieldType;
MEDPresentation::TypeID _fieldHandlerId;
std::string _rangeVar;
private:
- ///! Pipeline elements
-// std::vector<PyObjectId> _pipeline;
-
- ///! Corresponding display object, if any:
-// std::vector<PyObjectId> _display;
-
///! Presentation properties <key,value>
std::map<std::string, std::string> _propertiesStr;
std::map<std::string, int> _propertiesInt;
// Set number of contours
setNumberContours();
- colorBy("POINTS"); // necessarily POINTS because of the conversion above
+ colorBy("POINTS"); // necessarily POINTS because of the conversion above
showScalarBar();
selectColorMap();
rescaleTransferFunction();
// Compute cell average size in the mesh to have a nice scaling ratio:
std::ostringstream oss;
- oss << "import medcalc; __avgSize=medcalc.ComputeCellAverageSize(" << _srcObjVar << ");";
+ oss << "__avgSize = medcalc.ComputeCellAverageSize(" << _srcObjVar << ");";
pushAndExecPyLine(oss.str()); oss.str("");
colorBy("POINTS"); // like in Contour
pushAndExecPyLine(_objVar + " = " + _srcObjVar);
showObject();
- colorBy(_fieldType);
+
+ colorBy(_pvFieldType);
showScalarBar();
selectColorMap();
rescaleTransferFunction();
resetCameraAndRender();
-
- // Retrieve Python object for internal storage:
-// PyObject* p_obj = getPythonObjectFromMain(obj.c_str());
-// PyObject* p_disp = getPythonObjectFromMain(disp.c_str());
-// pushPyObjects(std::make_pair(_objId, p_obj), std::make_pair(disp_id, p_disp));
}
void
int nbSlices = getIntProperty(MEDPresentationSlices::PROP_NB_SLICES);
std::string normal = getNormalVector();
- oss << "import medcalc; __origins = medcalc.GetSliceOrigins(" << _srcObjVar << ", " << nbSlices << ", " << normal << ");";
+ oss << "__origins = medcalc.GetSliceOrigins(" << _srcObjVar << ", " << nbSlices << ", " << normal << ");";
pushAndExecPyLine(oss.str()); oss.str("");
pushAndExecPyLine("__objLst = [];");
oss << "for sliceNum in range(" << nbSlices << "):\n";
generateSlices();
showObject();
- colorBy(_fieldType);
+ colorBy(_pvFieldType);
showScalarBar();
selectColorMap();
rescaleTransferFunction();
MEDPresentationVectorField::autoScale()
{
std::ostringstream oss;
- oss << "import medcalc;";
- pushAndExecPyLine(oss.str()); oss.str("");
+// oss << "import medcalc;";
+// pushAndExecPyLine(oss.str()); oss.str("");
oss << _objVar << ".ScaleFactor = 2.0*medcalc.ComputeCellAverageSize(__srcObj0)/(" << _rangeVar
<< "[1]-" << _rangeVar << "[0]);";
pushAndExecPyLine(oss.str()); oss.str("");
showObject(); // to be done first so that the scale factor computation properly works
- oss << _objVar << ".Scalars = ['"<< _fieldType << "', 'None'];";
+ oss << _objVar << ".Scalars = ['"<< _pvFieldType << "', 'None'];";
pushAndExecPyLine(oss.str()); oss.str("");
- oss << _objVar << ".Vectors = ['"<< _fieldType << "', '" << _fieldName << "'];";
+ oss << _objVar << ".Vectors = ['"<< _pvFieldType << "', '" << _fieldName << "'];";
pushAndExecPyLine(oss.str()); oss.str("");
oss << _objVar << ".ScaleMode = 'vector';";
pushAndExecPyLine(oss.str()); oss.str("");
from medcalc_testutils import GetMEDFileDirTUI
datafile = os.path.join(GetMEDFileDirTUI(), "deplacements.med")
+#datafile = os.path.join(GetMEDFileDirTUI(), "/home/ab205030/beton_arme_30_officiel.med")
source_id = medcalc.LoadDataSource(datafile)
-presentation_id = medcalc.MakeDeflectionShape(accessField(0), viewMode=MEDCALC.VIEW_MODE_REPLACE,
+# For "beton_arme_30_officiel.med", field 7 = __DEPL__ (NODES)
+# For "deplacements", field 0 = DEP1 (NODES)
+presentation_id = medcalc.MakeDeflectionShape(accessField(7), viewMode=MEDCALC.VIEW_MODE_REPLACE,
colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW,
scalarBarRange=MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP
)
from medpresentation import UpdatePointSprite
from medpresentation import UpdateDeflectionShape
-from medpresentation import ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins
+from medpresentation import ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins, SelectSourceField
# Console commands
import medconsole
origins.append(orig_j)
return origins
+def SelectSourceField(obj, meshName, fieldName, discretisation):
+ """
+ Properly set the AllArrays property of a MEDReader source to point to the correct field.
+ """
+ tree = obj.GetProperty("FieldsTreeInfo")[::2]
+ it = None
+ for t in tree:
+ arr = t.split("/")
+ arr = arr[:-1] + arr[-1].split("@@][@@")
+ if arr[1] == meshName and arr[3] == fieldName and arr[4] == discretisation:
+ obj.AllArrays = [t]
+ return
+ raise Exception("Field not found")