_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);
//}
+