Utilities

Collection of functions for the Fem module.

This module contains function for managing a analysis and all the differnet types of objects it contains, helper for executing a simulation, function for extracting relevant parts of geometry and a few unrelated function useful at various places in the Fem module.

femtools.femutils.createObject(doc, name, proxy, viewProxy)

Add python object to document using python type string.

Add a document object suitable for the proxy and the viewProxy to doc and attach it to the proxy and the viewProxy. This function can only be used with python proxies that specify their C++ type via the BaseType class member (e.g. Cube.BaseType). If there already exists a object with name a suitable unique name is generated. To auto generate a name pass "".

Parameters
  • doc – document object to which the object is added

  • name – string of the name of new object in doc, use "" to generate a name

  • proxy – python proxy for new object

  • viewProxy – view proxy for new object

Returns

reference to new object

femtools.femutils.findAnalysisOfMember(member)

Find Analysis the member belongs to.

Parameters

member – a document object

Returns

If a analysis that contains member can be found a reference is returned. If no such object exists in the document of member, None is returned.

femtools.femutils.getBoundBoxOfAllDocumentShapes(doc)

Calculate bounding box containing all objects inside doc.

Returns

A bounding box containing all objects that have a Shape attribute (all Part and PartDesign objects). If the document contains no such objects or no objects at all return None.

femtools.femutils.getSelectedFace(selectionex)

Return selected face if exactly one face is selected.

Returns

The selcted face as a Part::TopoShape if exactly one face is selected. Otherwise return None.

Parameters

selectionex – A list of selection object like the one Gui.Selection.getSelectionEx() returns.

femtools.femutils.get_member(analysis, t)

Return list of all members of analysis of type t.

Search analysis for members of type t. This method checks the custom python typesytem (BaseType class property) used by the Fem module if possible. If the object doens’t use the python typesystem the usual isDerivedFrom from the C++ dynamic type system is used.

Parameters
  • analysis – only objects part of this analysis are considered

  • t – only objects of this type are returned

Note

Inheritance of Fem types is not checked. If obj uses Fems typesystem the type is just checked for equality. If the type doesn’t match obj.isDerivedFrom is called as usual. See https://forum.freecadweb.org/viewtopic.php?f=10&t=32625

femtools.femutils.get_mesh_to_solve(analysis)

Find one and only mesh object of analysis.

Returns

A tuple (object, message). If and only if the analysis contains exactely one mesh object the first value of the tuple is the mesh document object. Otherwise the first value is None and the second value is a error message indicating what went wrong.

femtools.femutils.get_pref_working_dir(solver_obj)

Return working directory for solver honoring user settings.

Throws femsolver.run.MustSaveError

If user setting is set to BESIDE and the document isn’t saved.

Note

Not working correctely for most cases because this circumvents directory caching of the solver framework. For solver use getMachine from run.py instead.

femtools.femutils.get_refshape_type(fem_doc_object)

Return shape type the constraints references.

Determine single shape type of references of fem_doc_object which must be a constraint (=have a References property). All references must be of the same type which is than returned as a string. A type can be “Vertex”, “Edge”, “Face” or “Solid”.

Parameters

fem_doc_object – A constraint object with a References property.

Returns

A string representing the shape type (“Vertex”, “Edge”, “Face” or “Solid”). If fem_doc_object isn’t a contraint "" is returned.

Note

Undefined behaviour if the type of the references of one object arn’t all the same.

Note

Undefined behaviour if constraint contains no references (empty list).

femtools.femutils.get_several_member(analysis, t)

Get members and pack them for Calculix/Z88.

Collect members by calling get_member() and pack them into a data structure that can be consumed by calculix and Z88 solver modules.

Parameters
Returns

A list containing one dict per member. Each dict has two entries: "Object" and "RefShapeType". dict["Object"] contains the member document object. dict["RefShapeType"] contains the shape type of the References property of the member (used by constraints) as a string (“Vertex”, “Edge”, “Face” or “Solid”). If the member doesn’t have a References property dict["RefShapeType"] is the empty string "".

Note

Undefined behaviour if one of the members has a References property which is empty.

Note

Undefined behaviour if the type of the references of one object arn’t all the same.

Note

Inheritance of Fem types is not checked. If obj uses Fems typesystem the type is just checked for equality. If the type doesn’t match obj.isDerivedFrom is called as usual. See https://forum.freecadweb.org/viewtopic.php?f=10&t=32625

femtools.femutils.get_single_member(analysis, t)

Return one object of type t and part of analysis.

Search analysis for members of type t and return the first one that’s found. This method checks the custom python typesytem (BaseType class property) used by the Fem module if possible. If the object doesn’t use the python typesystem the usual isDerivedFrom from the C++ dynamic type system is used.

Parameters
  • analysis – only objects part of this analysis are considered

  • t – only a object of this type is returned

Note

Inheritance of Fem types is not checked. If obj uses Fems typesystem the type is just checked for equality. If the type doesn’t match obj.isDerivedFrom is called as usual. See https://forum.freecadweb.org/viewtopic.php?f=10&t=32625

femtools.femutils.is_derived_from(obj, t)

Check if obj is derived from t honoring Fems typesytem.

Essentially just call obj.isDerivedFrom(t) and return it’s value. For objects using Fems typesystem (see type_of_obj()) return always True if the Fem type is equal to t.

Note

Inheritance of Fem types is not checked. If obj uses Fems typesystem the type is just checked for equality. If the type doesn’t match obj.isDerivedFrom is called as usual. See https://forum.freecadweb.org/viewtopic.php?f=10&t=32625

femtools.femutils.is_of_type(obj, ty)

Compare type of obj with ty honoring Fems typesystem.

See type_of_obj() for more info about the special typesystem of the Fem module.

Returns

True if obj is of type ty, False otherwise. Type must match exactely: Derived objects are not considered to be of type of one of their super classes.

femtools.femutils.pydecode(bytestring)

Return bytestring as a unicode string for python 2 and 3.

For python 2 bytestring is converted to a string of type unicode. For python 3 it is returned as is because it uses unicode for it’s str type already.

femtools.femutils.type_of_obj(obj)

Return type of obj honoring the special typesystem of Fem.

Python objects of the Fem workbench define their type via a class member <Class>.Type. Return this type if the property exists. If not return the conventional TypeId value.

Para obj

a document object