feature: general initial value and body source, to be tested

About the development of the FEM module/workbench.

Moderator: bernd

qingfeng.xia
Posts: 209
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford Uk
Contact:

Re: feature: general initial value and body source, to be tested

Postby qingfeng.xia » Thu Feb 20, 2020 6:06 pm

Thank you for your effort, I will pull your branch, to do more code chck.
+ I can make a unit test
+ for naming and place to put them, I will hear your advice, and other forumers.
bernd wrote:
Thu Feb 20, 2020 7:43 am
I did a lot of code formating to make the code fit in https://github.com/FreeCAD/FreeCAD/blob ... entions.md

Furthermore I fixed some problems. It compiles and it is possible to add the constraints to the document. So far so good, but there is still work to do.

- unit test
- I am not yet happy with the names
- the initial values for the two implemented constraints based on these general constraints is in ObjectsFem module. They might need to be somewhere else.

I really like these general constraints, but we need to improve it's implementation.
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Currently I mainly work on OpenFOAM + Fenics for CFD, FSI
https://github.com/qingfengxia/FreeCAD_Mod_Dev_Guide
https://github.com/qingfengxia/Cfd
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Thu Feb 20, 2020 7:48 pm

the new objects need to be added here https://github.com/FreeCAD/FreeCAD/blob ... _object.py
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Thu Feb 20, 2020 10:02 pm

but body source could be a constraint acting on a vertex. For example we could implement the constraint displacement as body source constraint.

Or would this be a generic initial value constraint?

Self weight would be a generic initial value constraint, than?
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Fri Feb 21, 2020 5:52 am

just because we need to present two objects to the user, it does mean we need to implement two objects.

Slowly I get an idea. May be we only make one base object, FemConstraintGeneric.

All these new constraints are inherited from this.

BTW: do you have abetter example than Initial Temperatur? Since this exists already as object and in writers of elmer and ccx I would like to keep it ATM. Better implement some new constraint because of problems in the regard of backward compatibility. We could move existant contraints if this new generic object has proven to be useful for some time in master.
qingfeng.xia
Posts: 209
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford Uk
Contact:

Re: feature: general initial value and body source, to be tested

Postby qingfeng.xia » Fri Feb 21, 2020 10:42 am

I agree there may be no need of 2 classes "InitialValue" and "BodySource", but for sure need 2 functions, makeInitialValue(), makeBodySource(), or even more, makeHeatSource, makeSelfWeight() , et, to help script users. while makeAcceleration() is a better way than selfWeght, see Ansys FEM, there is centrifual, linear acceleration.

I would love the idea, "FemConstraintGeneric", that is why cfd module only got one Contraint. instead of 10+.
TaskPanel can be shared, just fill the UI with different label, unit, etc, it is then data-driven UI design.

Here is new design proposal
1) base class: "FemConstraintGeneric"

1.1) ShapeTypeList property may be sufficient, there is no need for those below
also an optional: PreferedShapeType

1.2) "Category" enum property:
Source
InitialValue
Constraint


1.3) References: to select geometry apply the constraint to

1.4) Settings: PythonObject

"ConstraintType" property, is reserved to name more specific type
"Velocity" "Pressure"? or let user specify in Settings python dict

2) view provider and task can be shared, but icon can selected according to Category
so they can have different icons and limited geometry selection to only one type, to reduce chance of selection error by mouse. FEM constraint can apply to point, edge, face, body, but for other domains, one boudnary condition type can only apply to one kind of topo.

3) Further, makePressureConstraint() and PressureConstraintCommand .. otherwise, too much abstraction will make users' life hard.

4) It does not enforce any constraint must derived from that generic class, if this constraint is so special.

In the longer term: geometry selecton widget, may add support of
1) link to imported femsmeshset/group(Joha2's commit) to support external imported mesh (Cfd module has this method)
2) a way to select internal edge, body, etc. I know there is some ongoing work.
3) body source and initial value may need some box, sphere parameters to define a region, but it is not real geometry.
4) if Coin drawing can be customized in Python, then lots of C++ contraints can retire. at least do not add more to C++.

The current widget, does not support Quantity, because there is an issue, any new quantity unit needs to be registered to work properly, while I donot know. see the bug description in my another thread.
but body source could be a constraint acting on a vertex. For example we could implement the constraint displacement as body source constraint.
Or would this be a generic initial value constraint?
Self weight would be a generic initial value constraint, than?



There is no such term InitialValueConstraint, we'd better call it just "InitialValue". Vertex constraint and point body source, they are different concept from user's view. At GUI, TUI level, they should be split into 2. my opinion.
bernd wrote:
Fri Feb 21, 2020 5:52 am
just because we need to present two objects to the user, it does mean we need to implement two objects.

Slowly I get an idea. May be we only make one base object, FemConstraintGeneric.

All these new constraints are inherited from this.

BTW: do you have abetter example than Initial Temperatur? Since this exists already as object and in writers of elmer and ccx I would like to keep it ATM. Better implement some new constraint because of problems in the regard of backward compatibility. We could move existant contraints if this new generic object has proven to be useful for some time in master.
Last edited by qingfeng.xia on Fri Feb 21, 2020 3:02 pm, edited 2 times in total.
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Currently I mainly work on OpenFOAM + Fenics for CFD, FSI
https://github.com/qingfengxia/FreeCAD_Mod_Dev_Guide
https://github.com/qingfengxia/Cfd
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Fri Feb 21, 2020 12:29 pm

+1 ... we are on the same road 8-)

but as said, I would start with new conzraints first before touching the existing ones. They have been proven to work so far.
qingfeng.xia
Posts: 209
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford Uk
Contact:

Re: feature: general initial value and body source, to be tested

Postby qingfeng.xia » Fri Feb 21, 2020 10:56 pm

PR sent to your fembodyconstraint branch
https://github.com/berndhahnebach/FreeCAD_bhb/pull/63

BodySourceWidget -> ConstraintInputWidget

merged InitialValue and BodySource into FemGenericConstraint

FemBodyAcceleration -> FemConstraintAcceleration

InitialPressure instead of InitialTemperature as a demonstration of usage

Unit test passed

---
There are still minor issues

1. _FemGenericConstraint.py has PropertyPythonObject, all those I have made dump __state__() __setstate__()
I got error `<class 'TypeError'>: Object of type 'FeaturePython' is not JSON serializable` during saving, although my data change can be saved and later read bakc.

2. _ViewProviderFemGenericConstraint.py, I would like to change icon according to category, but it seems failed to load icon

Code: Select all

class _ViewProvider(ViewProviderFemConstraint.ViewProxy):

    def __init__(self, vobj):
        vobj.Proxy = self
        self.obj = vobj.Object  # needed in getIcon()

    def getIcon(self):
        # todo: dynamically generate icon by overlaying physical field symbol
        if "Category" in self.obj.PropertiesList:
            if self.obj.Category == "Source":
                return ":/icons/fem-add-body-source"
            elif self.obj.Category == "InitialValue":
                return ":/icons/fem-add-initial-value"
            else:
                return ":/icons/fem-add-initial-value"  # todo: fem-generic-constraint  
        else:
            FreeCAD.Console.Error("Document object does not have Category property")
            return ":/icons/fem-add-initial-value"  # todo: fem-generic-constraint

Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Currently I mainly work on OpenFOAM + Fenics for CFD, FSI
https://github.com/qingfengxia/FreeCAD_Mod_Dev_Guide
https://github.com/qingfengxia/Cfd
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Sun Feb 23, 2020 9:37 am

is InitialValue a constraint or a new object type besides contraint-, geometry- and material objects which is just inherited from the generic constraint.
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Sun Feb 23, 2020 3:36 pm

https://github.com/berndhahnebach/FreeC ... get.py#L96

Code: Select all

            self.componentLabels = ["x-component", "x-component", "x-component"]
Why three times x-component?
User avatar
bernd
Posts: 10184
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: feature: general initial value and body source, to be tested

Postby bernd » Mon Feb 24, 2020 8:55 pm

IMHO it shoudl be named FemConstraintGeneric instead FemGenericConstraint