3. Groove based workpiece data and geometry#
This tutorial covers:
Working with workpiece related data that can be described by a 2 dimensional groove and a seam length
Opening and navigating through WelDX files (tutorial)
# download the example file for this tutorial from util import download_tutorial_input_file download_tutorial_input_file(print_status=False)
3.2. Plotting the specimen’s groove#
An important piece that will be part of most WelDX files is the specimen data. The complexity of a specimen can range from a single metal plate to complex 3 dimensional multi-part structures. In this tutorial, we will discuss specimen geometries based on a 2-dimensional cross-section that is extruded into 3d space.
First we open the example file and examine the workpiece information.
from weldx import WeldxFile wxfile = WeldxFile("single_pass_weld.wx")
/home/docs/checkouts/readthedocs.org/user_builds/weldx/conda/latest/lib/python3.9/site-packages/asdf/asdf.py:340: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/weldx/checkouts/latest/doc/src/tutorials/single_pass_weld.wx' was created with extension URI 'asdf://weldx.bam.de/weldx/extensions/weldx-0.1.1' (from package weldx==0.6.0), which is not currently installed warnings.warn(msg, AsdfWarning)
root (dict) ├─base_metal (dict) │ ├─common_name (str) │ └─standard (str) └─geometry (dict) ├─groove_shape (VGroove) └─seam_length (Quantity)
The workpiece data of this particular file consists of two parts:
base_metal field contains information about the composition of the specimens material, which is not relevant for this tutorial.
We are only interested in the
geometry section that is further divided into:
groove_shape describes the 2 dimensional cross-section of the specimen.
We can already see, that it is of type
This object is based on the V-Groove described by ISO 9692-1.
The norm specifies the shape of the groove by different shape parameters.
We could now inspect the different parameter values and look up what meaning they have.
However, this would be rather tedious.
A much simpler way is to use the
plot method of the groove object:
groove = wxfile["workpiece"]["geometry"]["groove_shape"] groove.plot()
Apart from the visual representation, the plot also contains all relevant information like the groove’s area and the ISO 9692-1 parameters.
3.3. Other cross-sections#
Not all specimens might have a cross-section that is described by a norm, or the norm it uses might simply be not considered in the WelDX API.
For such cases, WelDX provides a more generalized class called
It allows us to define arbitrary cross-sections based on simple geometric elements such as lines and arcs.
So be aware, that you might get a
Profile instead one of the available groove types out of a WelDX file.
In fact, all groove types are based on the
Profile class, and we can convert them with the
profile = groove.to_profile() type(profile)
We can plot the content of a
Profile the same way as we did before with the groove:
The only difference here is that we don’t get the additional, norm-related information.
3.4. 3d plot (matplotlib)#
We can also create a nice 3d plot from the groove and the seam length stored in the WelDX file.
All we need for this is the
Geometry class of WelDX.
It can be created from a groove or profile and a length:
from weldx import Geometry, LinearHorizontalTraceSegment, Trace t = Trace(LinearHorizontalTraceSegment(wxfile["workpiece"]["geometry"]["seam_length"])) geometry = Geometry(groove, t)
Now all that remains, you might have guessed it, is to call the plot method:
HINT: Uncomment the code in the next cell to enable interactive plots in jupyter notebooks
# %matplotlib widget
By default, the
plot method shows us the triangulatad data.
But you can also choose to only plot the control points.
This can be achieved by setting the
show_wireframe parameter to
The density of the triangle mesh or the point cloud can be controlled py the parameters
The first one sets the point density of the individual profiles, while the value of the second one influences, how many profiles are actually drawn.
Both parameters need to be specified as
You can simply import
weldx to use quantities or write them as unit string.
Both methods are depicted in the code section below:
from weldx import Q_ geometry.plot( profile_raster_width=Q_(0.25, "mm"), trace_raster_width="17cm", show_wireframe=False )
As you can see, we now got only 3 densely rendered profiles. Try some other values to figure out which setting suits you most.
The last command also demonstrates two different ways to provide a Quantity to function that expects.
We can either construct a quantity from a value and a unit like
Q_(0.25, "mm") or we can combine value and unit in a string as
The second approach does not require us to import
Q_ but it is limited to scalar values and only works for function parameters.
Another noteworthy thing we did in the last command is using length units of different magnitude (
This is totally fine since
weldx can handle all necessary conversions internally by utilizing the powerful Python package
3.5. 3d plot (k3d)#
In the previous section we learned how to generate simple 3d-plots from a groove and a seam length using the
plot relies on matplotlib as rendering backend.
We have already mentioned before that this is not ideal for 3d renderings.
weldx package offers an alternative for jupyter notebook users.
You can select the
k3d package as rendering backend as follows:
Now we got a nice 3d rendering of the geometry with a closed surface that we shift and turn as we like.
k3d uses equal axis scaling, we notice that the specimen appears to be rather slim.
The reason for this is that the provided groove types only specify the shape of the groove and not the actual specimen width.
But we can provide one during creation of the geometry using the
Note that this only works with groove types and not with a plain
geometry_2 = Geometry(groove, t, width="20cm")
Now lets plot the geometry again:
geometry_2.plot(profile_raster_width="5mm", trace_raster_width="16cm", backend="k3d")
3.6. Export 3d geometry into a CAD file#
Geometry class also features a
It allows you to export the 3d data to different file formats like
Using this function, you can inspect the geometry in a CAD program or model viewer of your choice:
geometry.to_file( "weldx_geometry.stl", profile_raster_width="5mm", trace_raster_width="50mm" )
trace_raster_width do have the exact same effect as in the
plot method described before.
In this tutorial we have learned that WelDX can store geometrical data in form of a 2d-cross section and an extrusion length.
The 2d cross-section can either be of a specialized groove type or a more general
Both can be visualized using the
plot function and turned into an actual 3d geometry using the
Geometry class itself can also be rendered in a 3d plot and exported to a CAD compatible file format.