Skip to content

Commit

Permalink
Fem: enable FemBodySource and FemInitialValue feature
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfengxia committed Dec 31, 2018
1 parent f4f1c78 commit 9cf13b1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -199,6 +199,8 @@ SET(FemObjectsScripts_SRCS
femobjects/_FemResultMechanical.py
femobjects/_FemSolverCalculix.py
femobjects/FemConstraint.py
femobjects/_FemBodySource.py
femobjects/_FemInitialValue.py
)

SET(FemAllScripts
Expand Down Expand Up @@ -276,6 +278,9 @@ SET(FemGuiScripts_SRCS
femguiobjects/_ViewProviderFemSolverCalculix.py
femguiobjects/FemSelectionWidgets.py
femguiobjects/ViewProviderFemConstraint.py
femguiobjects/_ViewProviderFemBodySource.py
femguiobjects/_ViewProviderFemInitialValue.py
femguiobjects/BodyConstraintWidget.py
)


Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Fem/Gui/Resources/Fem.qrc
Expand Up @@ -8,6 +8,8 @@
<file>icons/fem-add-fem-mesh.svg</file>
<file>icons/fem-add-material.svg</file>
<file>icons/fem-add-part.svg</file>
<file>icons/fem-add-body-source.svg</file>
<file>icons/fem-add-initial-value.svg</file>

<file>icons/fem-analysis.svg</file>
<file>icons/fem-clipping-plane-add.svg</file>
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Fem/Gui/Workbench.cpp
Expand Up @@ -104,11 +104,13 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "Separator"
<< "FEM_ConstraintForce"
<< "FEM_ConstraintPressure"
<< "FEM_BodyAcceleration"
<< "FEM_ConstraintSelfWeight";

Gui::ToolBarItem* thermal = new Gui::ToolBarItem(root);
thermal->setCommand("Thermal Constraints");
*thermal << "FEM_ConstraintInitialTemperature"
<< "FEM_InitialTemperature"
<< "Separator"
<< "FEM_ConstraintTemperature"
<< "FEM_ConstraintHeatflux";
Expand Down Expand Up @@ -214,6 +216,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "FEM_ConstraintForce"
<< "FEM_ConstraintPressure"
<< "FEM_ConstraintSelfWeight"
<< "FEM_BodyAcceleration"
<< "Separator"
<< "FEM_ConstraintBearing"
<< "FEM_ConstraintGear"
Expand All @@ -222,6 +225,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
Gui::MenuItem* thermal = new Gui::MenuItem;
thermal->setCommand("&Thermal Constraints");
*thermal << "FEM_ConstraintInitialTemperature"
<< "FEM_InitialTemperature"
<< "Separator"
<< "FEM_ConstraintHeatflux"
<< "FEM_ConstraintTemperature"
Expand Down
35 changes: 32 additions & 3 deletions src/Mod/Fem/ObjectsFem.py
Expand Up @@ -43,7 +43,7 @@ def makeConstraintBearing(doc, name="ConstraintBearing"):
obj = doc.addObject("Fem::ConstraintBearing", name)
return obj


#DEPRECATED
def makeConstraintBodyHeatSource(doc, name="ConstraintBodyHeatSource"):
'''makeConstraintBodyHeatSource(document, [name]): makes a Fem ConstraintBodyHeatSource object'''
obj = doc.addObject("Fem::ConstraintPython", name)
Expand Down Expand Up @@ -118,7 +118,7 @@ def makeConstraintHeatflux(doc, name="ConstraintHeatflux"):
obj = doc.addObject("Fem::ConstraintHeatflux", name)
return obj


#DEPRECATED
def makeConstraintInitialFlowVelocity(doc, name="ConstraintInitialFlowVelocity"):
'''makeConstraintInitialFlowVelocity(document, [name]): makes a Fem ConstraintInitialFlowVelocity object'''
obj = doc.addObject("Fem::ConstraintPython", name)
Expand All @@ -129,13 +129,42 @@ def makeConstraintInitialFlowVelocity(doc, name="ConstraintInitialFlowVelocity")
_ViewProviderFemConstraintInitialFlowVelocity.ViewProxy(obj.ViewObject)
return obj


#DEPRECATED
def makeConstraintInitialTemperature(doc, name="ConstraintInitialTemperature"):
'''makeConstraintInitialTemperature(document, name): makes a Fem ConstraintInitialTemperature object'''
obj = doc.addObject("Fem::ConstraintInitialTemperature", name)
return obj


def makeBodySource(doc, bodySource, name="BodySource"):
'''makeBodySource(document, [name]): creates an body source such as heat source, gravity'''
if not (name) and bodySource and 'Name' in bodySource:
name = "BodySource" + bodySource['Name']
obj = doc.addObject("Fem::FeaturePython", name) # App::DocumentObject can not add dynamic property
from femobjects import _FemBodySource
_FemBodySource._FemBodySource(obj)
obj.BodySource = bodySource

if FreeCAD.GuiUp:
from femguiobjects import _ViewProviderFemBodySource
_ViewProviderFemBodySource._ViewProvider(obj.ViewObject)
return obj


def makeInitialValue(doc, initialValue, name="IntialValue"):
'''makeConstraintSelfWeight(document, [name]): creates an self weight object to define a gravity load'''
if not (name) and initialValue and 'Name' in initialValue:
name = initialValue['Name'] + 'InitialValue'
obj = doc.addObject("Fem::FeaturePython", name)
from femobjects import _FemInitialValue
_FemInitialValue._FemInitialValue(obj)
obj.InitialValue = initialValue
if FreeCAD.GuiUp:
from femguiobjects import _ViewProviderFemInitialValue
_ViewProviderFemInitialValue._ViewProvider(obj.ViewObject)
return obj


def makeConstraintPlaneRotation(doc, name="ConstraintPlaneRotation"):
'''makeConstraintPlaneRotation(document, [name]): makes a Fem ConstraintPlaneRotation object'''
obj = doc.addObject("Fem::ConstraintPlaneRotation", name)
Expand Down
53 changes: 53 additions & 0 deletions src/Mod/Fem/femcommands/commands.py
Expand Up @@ -105,6 +105,57 @@ def Activated(self):
FreeCADGui.doCommand("nodes = sg.getChildren()")
FreeCADGui.doCommand(line1 + line2 + line3)

# where is the best place to put these constants?
_DefaultInitialTemperature = "{'Name': 'Temperature', 'Symbol': u'T','ValueType': 'Expression', 'NumberOfComponents': 1, 'Unit': 'K', 'Value': 300}"
_DefaultBodyAcceleration = "{'Name': 'Acceleration', 'Symbol': u'g','ValueType': 'Quantity', 'NumberOfComponents': 3, 'Unit': 'm/s^2', 'Value': [0, 0, -9.8]}"

class _CommandFemInitialTemperature(CommandManager):
"The FEM_InitialTemperature command definition"
def __init__(self):
super(_CommandFemInitialTemperature, self).__init__()
self.resources = {
'Pixmap': 'fem-add-initial-value',
'MenuText': QtCore.QT_TRANSLATE_NOOP(
"FEM_InitialTemperature",
"initial temperature value"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP(
"FEM_InitialTemperature",
"Creates an initialtemperature value")}
self.is_active = 'with_analysis'

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create Fem InitialValue")
FreeCADGui.addModule("ObjectsFem")
# fill with a customised BodyConstrainSettings python dict
FreeCADGui.doCommand("bcs = {}".format(_DefaultInitialTemperature))
FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeInitialValue(FreeCAD.ActiveDocument, bcs))")
FreeCADGui.doCommand("FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)")
FreeCADGui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()


class _CommandFemBodyAcceleration(CommandManager):
"The FEM_BodyAcceleration command definition"
def __init__(self):
super(_CommandFemBodyAcceleration, self).__init__()
self.resources = {
'Pixmap': 'fem-add-body-source',
'MenuText': QtCore.QT_TRANSLATE_NOOP(
"FEM_BodyAcceleration",
"Constraint BodyAcceleration (gravity)"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP(
"FEM_BodyAcceleration",
"Creates a FEM body constraint of acceleration")}
self.is_active = 'with_analysis'

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create Fem BodyAcceleration")
FreeCADGui.addModule("ObjectsFem")
# make a customised BodyConstrainSettings python dict
FreeCADGui.doCommand("bcs = {}".format(_DefaultBodyAcceleration))
FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeBodySource(FreeCAD.ActiveDocument, bcs))")
FreeCAD.ActiveDocument.recompute()


class _CommandFemConstraintBodyHeatSource(CommandManager):
"The FEM_ConstraintBodyHeatSource command definition"
Expand Down Expand Up @@ -840,6 +891,8 @@ def Activated(self):
FreeCADGui.addCommand('FEM_ConstraintFlowVelocity', _CommandFemConstraintFlowVelocity())
FreeCADGui.addCommand('FEM_ConstraintInitialFlowVelocity', _CommandFemConstraintInitialFlowVelocity())
FreeCADGui.addCommand('FEM_ConstraintSelfWeight', _CommandFemConstraintSelfWeight())
FreeCADGui.addCommand('FEM_InitialTemperature', _CommandFemInitialTemperature())
FreeCADGui.addCommand('FEM_BodyAcceleration', _CommandFemBodyAcceleration())
FreeCADGui.addCommand('FEM_ElementFluid1D', _CommandFemElementFluid1D())
FreeCADGui.addCommand('FEM_ElementGeometry1D', _CommandFemElementGeometry1D())
FreeCADGui.addCommand('FEM_ElementGeometry2D', _CommandFemElementGeometry2D())
Expand Down

0 comments on commit 9cf13b1

Please sign in to comment.