FEM: result object refactor, move most properties from C++ to a new Python result object

This commit is contained in:
qingfengxia
2017-02-16 07:54:32 +01:00
committed by Bernd Hahnebach
parent ea1829c9fa
commit c13ca92792
8 changed files with 187 additions and 32 deletions

2
src/Mod/Fem/App/CMakeLists.txt Executable file → Normal file
View File

@@ -109,6 +109,7 @@ SET(FemScripts_SRCS
_ViewProviderFemSolverCalculix.py
_ViewProviderFemSolverZ88.py
_ViewProviderFemMaterial.py
_ViewProviderFemResult.py
ccxDatReader.py
ccxFrdReader.py
convert2TetGen.py
@@ -139,6 +140,7 @@ SET(FemScripts_SRCS
FemToolsCcx.py
FemToolsZ88.py
FemMaterial.py
FemResult.py
FemSelectionObserver.py
TestFem.py
TaskPanelFemBeamSection.ui

View File

@@ -38,8 +38,12 @@ PROPERTY_SOURCE(Fem::FemResultObject, App::DocumentObject)
FemResultObject::FemResultObject()
{
ADD_PROPERTY_TYPE(Mesh,(0), "General",Prop_None,"Link to the corresponding mesh");
ADD_PROPERTY_TYPE(NodeNumbers,(0), "Data",Prop_None,"Numbers of the result nodes");
ADD_PROPERTY_TYPE(Stats,(0), "Fem",Prop_None,"Statistics of the results");
ADD_PROPERTY_TYPE(Time,(0), "Fem",Prop_None,"Time of analysis incement");
/*
ADD_PROPERTY_TYPE(DisplacementVectors,(), "Fem",Prop_None,"List of displacement vectors");
ADD_PROPERTY_TYPE(DisplacementLengths,(0), "Fem",Prop_None,"List of displacement lengths");
ADD_PROPERTY_TYPE(StressVectors,(), "Fem",Prop_None,"List of Stress vectors");
@@ -50,15 +54,16 @@ FemResultObject::FemResultObject()
ADD_PROPERTY_TYPE(PrincipalMin,(0), "Fem",Prop_None,"List of Third Principal (Min) stress values");
ADD_PROPERTY_TYPE(MaxShear,(0), "Fem",Prop_None,"List of Maximum Shear stress values");
ADD_PROPERTY_TYPE(Temperature,(0), "Fem",Prop_None,"Nodal temperatures");
ADD_PROPERTY_TYPE(Mesh,(0), "General",Prop_None,"Link to the corresponding mesh");
ADD_PROPERTY_TYPE(Eigenmode,(0), "Fem",Prop_None,"Number of the eigenmode");
ADD_PROPERTY_TYPE(EigenmodeFrequency,(0), "Fem",Prop_None,"Frequency of the eigenmode");
ADD_PROPERTY_TYPE(Time,(0), "Fem",Prop_None,"Time of analysis incement");
ADD_PROPERTY_TYPE(UserDefined,(0), "Fem",Prop_None,"User Defined Results");
*/
// make read-only for property editor
NodeNumbers.setStatus(App::Property::ReadOnly, true);
Stats.setStatus(App::Property::ReadOnly, true);
Time.setStatus(App::Property::ReadOnly, true);
/*
DisplacementVectors.setStatus(App::Property::ReadOnly, true);
DisplacementLengths.setStatus(App::Property::ReadOnly, true);
StressVectors.setStatus(App::Property::ReadOnly, true);
@@ -71,8 +76,8 @@ FemResultObject::FemResultObject()
Temperature.setStatus(App::Property::ReadOnly, true);
Eigenmode.setStatus(App::Property::ReadOnly, true);
EigenmodeFrequency.setStatus(App::Property::ReadOnly, true);
Time.setStatus(App::Property::ReadOnly, true);
UserDefined.setStatus(App::Property::ReadOnly, false);
* */
}
FemResultObject::~FemResultObject()

View File

@@ -46,35 +46,12 @@ public:
/// Link to the corresponding mesh
App::PropertyLink Mesh;
/// Stats of analysis
App::PropertyFloatList Stats;
/// Displacement vectors of analysis
App::PropertyVectorList DisplacementVectors;
/// Lengths of displacement vectors of analysis
App::PropertyFloatList DisplacementLengths;
/// Stress vectors of analysis
App::PropertyVectorList StressVectors;
/// Strain vectors of analysis
App::PropertyVectorList StrainVectors;
/// Von Mises Stress values of analysis
App::PropertyFloatList StressValues;
/// First principal Stress values of analysis
App::PropertyFloatList PrincipalMax;
/// Second principal Stress values of analysis
App::PropertyFloatList PrincipalMed;
/// Third principal Stress values of analysis
App::PropertyFloatList PrincipalMin;
/// Shear Stress values of analysis
App::PropertyFloatList MaxShear;
/// Temperature
App::PropertyFloatList Temperature;
/// Eigenmode
App::PropertyInteger Eigenmode;
/// Eigenmode frequency
App::PropertyFloat EigenmodeFrequency;
/// Increment time
App::PropertyFloat Time;
/// User defined results
App::PropertyFloatList UserDefined;
App::PropertyFloatList Stats;
/// Displacement vectors of analysis
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {

View File

@@ -126,6 +126,8 @@ INSTALL(
# additional imports and exports
importVTKResults.py
FemResult.py
_ViewProviderFemResult.py
DESTINATION
Mod/Fem

90
src/Mod/Fem/FemResult.py Normal file
View File

@@ -0,0 +1,90 @@
#***************************************************************************
#* *
#* Copyright (c) 2016 - Qingfeng Xia <qingfeng.xia()eng.ox.ac.uk> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
__title__ = "DocumentOject Class to hold Fem result"
__author__ = "Qingfeng Xia"
__url__ = "http://www.freecadweb.org"
import FreeCAD
import Fem
def makeFemResult(result_obj_name):
obj= FreeCAD.ActiveDocument.addObject('Fem::FemResultObjectPython', result_obj_name)
# detect domain later, CFD or Mechanical later
_MechanicalResult(obj)
if FreeCAD.GuiUp:
from _ViewProviderFemResult import _ViewProviderFemResult
_ViewProviderFemResult(obj.ViewObject)
return obj
class _MechanicalResult(object):
def __init__(self, obj):
self.Type = "MechanicalResult"
self.Object = obj # keep a ref to the DocObj for nonGui usage
obj.Proxy = self # link between App::DocumentObject to this object
# `Time, Stats` should have been defined in base cpp class
obj.addProperty("App::PropertyVectorList", "DisplacementVectors", "Fem",
"List of displacement vectors", True) # does not show up in propertyEditor of combiView
obj.addProperty("App::PropertyVectorList", "StressVectors", "Fem",
"List of stress vectors", True) # does not show up in propertyEditor of combiView
obj.addProperty("App::PropertyVectorList", "StrainVectors", "Fem",
"List of strain vectors", True) # does not show up in propertyEditor of combiView
obj.addProperty("App::PropertyFloatList", "DisplacementLengths", "Fem",
"List of displacement lengths", True) # readonly in propertyEditor of combiView
obj.addProperty("App::PropertyFloatList", "StressValues", "Fem",
"", True)
obj.addProperty("App::PropertyFloatList", "PrincipalMax", "Fem",
"", True)
obj.addProperty("App::PropertyFloatList", "PrincipalMed", "Fem",
"", True)
obj.addProperty("App::PropertyFloatList", "PrincipalMin", "Fem",
"", True)
obj.addProperty("App::PropertyFloatList", "MaxShear", "Fem",
"List of Maximum Shear stress values", True)
obj.addProperty("App::PropertyFloatList", "UserDefined", "Fem",
"User Defined Results", True)
# temperature field is needed in the thermal stress analysis
obj.addProperty("App::PropertyFloatList", "Temperature", "Fem",
"Temperature field", True)
# for frequency analysis
obj.addProperty("App::PropertyInteger", "Eigenmode", "Fem",
"", True)
obj.addProperty("App::PropertyFloat", "EigenmodeFrequency", "Fem",
"User Defined Results", True)
############ standard FeutureT methods ##########
def execute(self, obj):
""""this method is executed on object creation and whenever the document is recomputed"
update Part or Mesh should NOT lead to recompution of the analysis automatically, time consuming
"""
return
def onChanged(self, obj, prop):
return
def __getstate__(self):
return self.Type
def __setstate__(self, state):
if state:
self.Type = state

View File

@@ -45,12 +45,13 @@ ViewProviderResult::~ViewProviderResult()
}
/* not needed since _ViewProviderFemResult.py is made
bool ViewProviderResult::doubleClicked(void)
{
Gui::Command::runCommand(Gui::Command::Gui, "Gui.runCommand('Fem_ShowResult')");
return true;
}
*/
// Python feature -----------------------------------------------------------------------

View File

@@ -45,7 +45,7 @@ public:
virtual bool isShow(void) const
{ return true; }
bool doubleClicked(void);
//bool doubleClicked(void);
};
typedef Gui::ViewProviderPythonFeatureT<ViewProviderResult> ViewProviderResultPython;

View File

@@ -0,0 +1,78 @@
#***************************************************************************
#* *
#* Copyright (c) 2015 - Qingfeng Xia <qingfeng.xia()eng.ox.ac.uk> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
__title__ = "ViewProvider for Fem ResultObjectPython"
__author__ = "Qingfeng Xia"
__url__ = "http://www.freecadweb.org"
import FreeCAD
import FreeCADGui
import FemGui
class _ViewProviderFemResult:
"""A View Provider for the FemResultObject Python dervied FemResult class
"""
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
"""after load from FCStd file, self.icon does not exist, return constant path instead"""
return ":/icons/fem-result.svg"
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
def updateData(self, obj, prop):
return
def onChanged(self, vobj, prop):
return
def doubleClicked(self, vobj):
if FreeCADGui.activeWorkbench().name() != 'FemWorkbench':
FreeCADGui.activateWorkbench("FemWorkbench")
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Active Task Dialog found! Please close this one first!\n')
return True
def setEdit(self, vobj, mode):
#if FemGui.getActiveAnalysis():
from _TaskPanelShowResult import _TaskPanelShowResult
taskd = _TaskPanelShowResult()
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
def __getstate__(self):
return None
def __setstate__(self, state):
return None