=========================
## features
Last year, I proposed a generalised body source (gravity, acceleration, heat source, ...) and generalised initial value for any variable, to reduce code duplication.
why? InitialValue is not important for linear elastic problem, but very useful for nonlinear PDE. Cfd workbench must have such obj. I see dicussion in Forum, using Macro to build a electroMagnetic simulation, I think there two objs could be helpful.
Finally, I have the time to implement: _FemBodySource, or _FemInitialValue.
It has the features:
1) apply to the whole domain or selected body (can be point source, internal face, body)
2) value support float value and string expression
3) generalised taskpanel "BodyConstraintWidget"
see a preview of body source, linear acceleration/gravity ## testing
branch: bodyconstraint https://github.com/qingfengxia/FreeCAD
`git clone https://github.com/qingfengxia/FreeCAD.git --branch bodyconstraint --single-branch`
based on freecad-daily 20181229
I had a basic test on ubuntu 16.04
Currently, these two objs are tested Cfd module, without recompiling FreeCAD project.
But if you compile my branch, you should be enable to test in Fem workbench.
Apparently, there is no solver to use them, but UI should show up.
## implementation details
1) FemBodySource and FemInitialValue has their own viewprovider and taskpanel, but share widget
`Category = 'BodySource' 'InitialValue' # similar as FemMaterial for Solid and Fluid`
2) Properties: 'References' to select specific body
'InitialValue'/'BodySource' Python dict to provide flexible settings
Code: Select all
= {'Name': 'Temperature', # name of physical field, used by commander to givev a better obj name
'Symbol': u'T', # can be used to generate variable specific icon file
'ValueType' 'Quantity', # "Expression"`
'NumberOfComponents': 1, # 'Scaler', 'Vector', 'Tensor'.
'Unit': 'C', # InputEdit of FreeCAD
'Value': [0] # can be list/tuple or just float, len() = NumberOfComponents
}
#This python dict can be further inserted with "Category" and "ShapeType"
4) commands.py has concrete command objects, I made 2 for the testing proposes
_FemCommandBodyAcceleration, which deprecates SelfWeight
Code: Select all
_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()
## to discuss:
1) if there is any name you dislike, please tell me, especially, the 'InitialValue'/'BodySource'
2) I provided default python settings dict, which file should I put them?
3) I was considering add "PhysicalField" property, "Temperature", "Pressure", "Velocity".
to make it easy to create concrete command object.
4) for body source, I am considering "BodySourceType", to support more advanced type like "Rotating acceleratoin",
Depends on BodySourceType, different taskpanel can be loaded.
5) any features you would like?
## Todo:
1) icon file, I am thinking about overlaying a symbol on svg icon file, but I have not got such technique.
2) Gui.InputField, I can not import InputField into python? currently it is a QDoubleSpinBox, min value is zero (this is a bug)
3) adoption of these 2 classes should be done by solver devoloper, there are some existing objects could be deprecated.
`SelfWeight = gravity/linear acceleration`
4) test on multi-body mesh and geometry. I do not have the time.
5) code review and pep8