From 9690b5f91b000958924a10491f28f8fd29ff5e76 Mon Sep 17 00:00:00 2001 From: abn Date: Fri, 5 Aug 2016 15:28:13 +0200 Subject: [PATCH] [MEDCalc] Added Gauss points treatment. ELNO to come. --- src/MEDCalc/cmp/MEDDataManager_i.cxx | 180 +++++++++-------- src/MEDCalc/cmp/MEDPresentation.cxx | 186 ++++++++++-------- src/MEDCalc/cmp/MEDPresentation.hxx | 19 +- src/MEDCalc/cmp/MEDPresentationContour.cxx | 2 +- .../cmp/MEDPresentationPointSprite.cxx | 2 +- src/MEDCalc/cmp/MEDPresentationScalarMap.cxx | 8 +- src/MEDCalc/cmp/MEDPresentationSlices.cxx | 4 +- .../cmp/MEDPresentationVectorField.cxx | 8 +- src/MEDCalc/test/tui/deflection_shape.py | 5 +- src/MEDCalc/tui/__init__.py | 2 +- src/MEDCalc/tui/medpresentation.py | 13 ++ 11 files changed, 232 insertions(+), 197 deletions(-) diff --git a/src/MEDCalc/cmp/MEDDataManager_i.cxx b/src/MEDCalc/cmp/MEDDataManager_i.cxx index f3f5b325a..f4b624323 100644 --- a/src/MEDCalc/cmp/MEDDataManager_i.cxx +++ b/src/MEDCalc/cmp/MEDDataManager_i.cxx @@ -82,9 +82,9 @@ MEDCALC::DatasourceHandler * MEDDataManager_i::loadDatasource(const char *filepa // 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 "<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 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 listOfTypes = GetTypesOfField(filepath, + meshName, + fieldName); + int nbOfTypes = listOfTypes.size(); + for (int iType = 0; iType < nbOfTypes; iType++) { + LOG("---- type "<, 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; iterationIdxuri; + 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); diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 43ce20db5..92c22a904 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -56,7 +56,8 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s _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://")) { @@ -129,7 +130,7 @@ void 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; @@ -209,6 +210,7 @@ MEDPresentation::getIntProperty(const std::string& propName) const { MEDPyLockWrapper lock; pushAndExecPyLine( "import pvsimple as pvs;"); + pushAndExecPyLine( "import medcalc"); } @@ -228,7 +230,7 @@ MEDPresentation::getPythonObjectFromMain(const char* python_var) const } std::string -MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const +MEDPresentation::getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const { switch(fieldType) { @@ -236,8 +238,10 @@ MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const 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 ""; } } @@ -250,14 +254,59 @@ MEDPresentation::getRenderViewVar() const 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 @@ -462,14 +511,14 @@ MEDPresentation::fillAvailableFieldComponents() 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()); } @@ -514,90 +563,61 @@ MEDPresentation::fillAvailableFieldComponents() 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); //} + diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index b60bb47b9..dc05e9fca 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -89,7 +89,6 @@ protected: 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); @@ -97,9 +96,7 @@ protected: void fillAvailableFieldComponents(); void applyCellToPointIfNeeded(); - void convertTo3DVectorField(); -// double computeCellAverageSize(); - //void computeFieldRange +// void convertTo3DVectorField(); // virtual MEDCALC::ViewModeType getViewMode() = 0; @@ -119,7 +116,7 @@ protected: 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(); @@ -131,7 +128,11 @@ protected: 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; @@ -154,12 +155,6 @@ protected: std::string _rangeVar; private: - ///! Pipeline elements -// std::vector _pipeline; - - ///! Corresponding display object, if any: -// std::vector _display; - ///! Presentation properties std::map _propertiesStr; std::map _propertiesInt; diff --git a/src/MEDCalc/cmp/MEDPresentationContour.cxx b/src/MEDCalc/cmp/MEDPresentationContour.cxx index e32b5ff2c..d8b6b48d8 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.cxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.cxx @@ -83,8 +83,8 @@ MEDPresentationContour::internalGeneratePipeline() // 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(); diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx index dfa7ddd17..e748b46fc 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx @@ -59,7 +59,7 @@ MEDPresentationPointSprite::internalGeneratePipeline() // 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 diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 78c228b50..ef8804a4e 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -53,16 +53,12 @@ MEDPresentationScalarMap::internalGeneratePipeline() 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 diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.cxx b/src/MEDCalc/cmp/MEDPresentationSlices.cxx index 09447d8ad..99c87041a 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.cxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.cxx @@ -45,7 +45,7 @@ MEDPresentationSlices::generateSlices() 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"; @@ -66,7 +66,7 @@ MEDPresentationSlices::generateAndDisplay() generateSlices(); showObject(); - colorBy(_fieldType); + colorBy(_pvFieldType); showScalarBar(); selectColorMap(); rescaleTransferFunction(); diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx index d1dde7836..a05075ed1 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx @@ -40,8 +40,8 @@ void 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(""); @@ -72,9 +72,9 @@ MEDPresentationVectorField::internalGeneratePipeline() 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(""); diff --git a/src/MEDCalc/test/tui/deflection_shape.py b/src/MEDCalc/test/tui/deflection_shape.py index 3c718687c..865e3282f 100644 --- a/src/MEDCalc/test/tui/deflection_shape.py +++ b/src/MEDCalc/test/tui/deflection_shape.py @@ -28,9 +28,12 @@ from medcalc.medconsole import accessField 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 ) diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 7dc847e5d..273b74a0c 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -64,7 +64,7 @@ from medpresentation import UpdateVectorField 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 diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index ea9574ab8..faa1e0eb0 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -216,3 +216,16 @@ def GetSliceOrigins(obj, nbSlices, normal): 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") -- 2.39.2