From 2b1bbd5e6c6d8866ae3acb082f78397a8d765408 Mon Sep 17 00:00:00 2001 From: Uwe Date: Sun, 27 Mar 2022 18:24:03 +0200 Subject: [PATCH] [FEM] fix value display in result pipelines - as reported here: https://forum.freecadweb.org/viewtopic.php?p=583133#p583133 The point is that the user cannot know that he has to multiply the shown numbers for displacements by 0.001 but for the displayed stresses by 1e6 while the temperature is already correct. The fix is to be consistent and display in SI units. This commit does this and was tested using unit systems with mm and meter based length. --- src/Mod/Fem/App/FemVTKTools.cpp | 47 ++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Mod/Fem/App/FemVTKTools.cpp b/src/Mod/Fem/App/FemVTKTools.cpp index d3c072c93e..2e3d8cb6cd 100644 --- a/src/Mod/Fem/App/FemVTKTools.cpp +++ b/src/Mod/Fem/App/FemVTKTools.cpp @@ -837,9 +837,13 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar SMESH_Mesh* smesh = const_cast(static_cast(meshObj)->FemMesh.getValue().getSMesh()); SMESHDS_Mesh* meshDS = smesh->GetMeshDS(); + // all result object meshes are in mm therefore for e.g. length outputs like + // displacement we must divide by 1000 + double factor = 1.0; + // vectors for (std::map::iterator it = vectors.begin(); it != vectors.end(); ++it) { - const int dim=3; //Fixme, detect dim, but FreeCAD PropertyVectorList ATM only has DIM of 3 + const int dim = 3; //Fixme, detect dim, but FreeCAD PropertyVectorList ATM only has DIM of 3 App::PropertyVectorList* field = nullptr; if (res->getPropertyByName(it->first.c_str())) field = static_cast(res->getPropertyByName(it->first.c_str())); @@ -858,17 +862,22 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar //we need to set values for the unused points. //TODO: ensure that the result bar does not include the used 0 if it is not part of the result (e.g. does the result bar show 0 as smallest value?) if (nPoints != field->getSize()) { - double tuple[] = {0,0,0}; - for (vtkIdType i=0; iSetTuple(i, tuple); } } + if (it->first.compare("DisplacementVectors") == 0) + factor = 0.001; + else + factor = 1.0; + SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator(); - for (std::vector::const_iterator jt=vel.begin(); jt!=vel.end(); ++jt) { + for (std::vector::const_iterator jt = vel.begin(); jt != vel.end(); ++jt) { const SMDS_MeshNode* node = aNodeIter->next(); - double tuple[] = {jt->x, jt->y, jt->z}; - data->SetTuple(node->GetID()-1, tuple); + double tuple[] = { jt->x * factor, jt->y * factor, jt->z * factor }; + data->SetTuple(node->GetID() - 1, tuple); } grid->GetPointData()->AddArray(data); Base::Console().Log(" The PropertyVectorList %s was exported to VTK vector list: %s\n", it->first.c_str(), it->second.c_str()); @@ -897,15 +906,33 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar //we need to set values for the unused points. //TODO: ensure that the result bar does not include the used 0 if it is not part of the result (e.g. does the result bar show 0 as smallest value?) if (nPoints != field->getSize()) { - for (vtkIdType i=0; iSetValue(i, 0); } - } + } + + if ((it->first.compare("MaxShear") == 0) + || (it->first.compare("MaxShear") == 0) + || (it->first.compare("NodeStressXX") == 0) + || (it->first.compare("NodeStressXY") == 0) + || (it->first.compare("NodeStressXZ") == 0) + || (it->first.compare("NodeStressYY") == 0) + || (it->first.compare("NodeStressYZ") == 0) + || (it->first.compare("NodeStressZZ") == 0) + || (it->first.compare("PrincipalMax") == 0) + || (it->first.compare("PrincipalMed") == 0) + || (it->first.compare("PrincipalMin") == 0) + || (it->first.compare("vonMises") == 0)) + factor = 1e6; + else if (it->first.compare("DisplacementLengths") == 0) + factor = 0.001; + else + factor = 1.0; SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator(); - for (size_t i=0; inext(); - data->SetValue(node->GetID()-1, vec[i]); + data->SetValue(node->GetID() - 1, vec[i] * factor); } grid->GetPointData()->AddArray(data);