Modify design variables and write out `.vspgeom` file from Python

324 views
Skip to first unread message

Daniel Ingraham

unread,
Sep 13, 2022, 9:48:35 AM9/13/22
to OpenVSP
Hi all,

I'd like to write a Python script that performs the following tasks:

* Reads in an existing `.vsp3` file.
* Sets the design variables associated with the `vsp3` file that I've specified previously via the Model->Design Variables tab in the OpenVSP GUI
* Writes out a thin `.vspgeom` of the modified geometry.

I have a first try at this in this gist: 

The script runs without any apparent errors, but the coordinates in the `.vspgeom` file don't change. I'm using the default Prop geometry, and just a single design variable for now (the feather angle of the propeller).

In the gist there is also an AngelScript that does the same task that appears to work fine, and the `.vsp3` file.

Any ideas what I'm doing wrong?

Thanks!

Daniel

Rob McDonald

unread,
Sep 13, 2022, 11:40:03 AM9/13/22
to ope...@googlegroups.com
I believe the problem is that you export the file twice in the same script without deleting the MeshGeom created during the export.  Your *.vspscript does not do this.

When you export a *.vspgeom file (and other triangle mesh formats), OpenVSP looks through the Geoms for a MeshGeom.  If it finds one, it exports it.  If it does not find one, it creates one and exports that.  It does not delete the resulting MeshGeom.

ExportFile() actually returns a string for the ID of the MeshGeom that is created.  So, you can pretty easily do something like...

id=vsp.ExportFile()
vsp.DeleteGeom(id)

Using the Design Variable file makes sense if you're using external tools to create the *.des file -- or if you just really like using the GUI to drag-n-drop your Parms to create the initial *.des file.

However, if you're doing everything from the Python API, you could just as easily use SetParmVal() either by ParmID, or by container, group, name.

Rob


--
You received this message because you are subscribed to the Google Groups "OpenVSP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openvsp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openvsp/3188c4d6-73a4-4dca-9d8d-d34a1e8096f2n%40googlegroups.com.

Daniel Ingraham

unread,
Sep 13, 2022, 1:06:44 PM9/13/22
to OpenVSP
> I believe the problem is that you export the file twice in the same script without deleting the MeshGeom created during the export.

Yes, that was the problem. Adding the call to `vsp.DeleteGeom` did the trick. Thanks!

> However, if you're doing everything from the Python API, you could just as easily use SetParmVal() either by ParmID, or by container, group, name.

I had forgotten about this functionality, thanks for the reminder. For anyone else following along, I fixed the problem with the `desvar_mwe.py` in the gist and added a version of the script called `parms_mwe.py` that does the same thing with `openvsp.GetParmVal` and `openvsp.SetParmVal`.

Last question: is it possible to get the coordinate locations of the MeshGeom that's written to the vspgeom from the Python API (i.e., other than reading it from the vspgeom file, like I'm doing in the Python scripts)?

Thanks again!

Daniel

Rob McDonald

unread,
Sep 13, 2022, 1:31:41 PM9/13/22
to ope...@googlegroups.com
On Tue, Sep 13, 2022 at 10:06 AM Daniel Ingraham <d.j.in...@gmail.com> wrote:
> I believe the problem is that you export the file twice in the same script without deleting the MeshGeom created during the export.

Yes, that was the problem. Adding the call to `vsp.DeleteGeom` did the trick. Thanks!

Great.  I hadn't actually tested your example, so I'm glad to receive the confirmation. 

 
> However, if you're doing everything from the Python API, you could just as easily use SetParmVal() either by ParmID, or by container, group, name.

I had forgotten about this functionality, thanks for the reminder. For anyone else following along, I fixed the problem with the `desvar_mwe.py` in the gist and added a version of the script called `parms_mwe.py` that does the same thing with `openvsp.GetParmVal` and `openvsp.SetParmVal`.

Last question: is it possible to get the coordinate locations of the MeshGeom that's written to the vspgeom from the Python API (i.e., other than reading it from the vspgeom file, like I'm doing in the Python scripts)?

Yes, there are a couple of ways of doing it.

One is to use:
resid = vsp.CreateGeomResults( geomid, name )

I'm not sure why this was not implemented as a normal 'Analysis' that produced results, but it wasn't.  The 'name' parameter is a name assigned to the results set, name it whatever you want.

If the geomid references a MeshGeom, then it will include an indexed triangle set -- i.e. a list of points and then a list of triangles specified by node ID's that point into that list of points.  Much like a Cart3D *.tri file.

If the geomid references a normal Geom, then it will output a simple structured mesh file with sets of cross sections.  Much like a XSec *.hrm file.

You can look in TestAll.vspscript for some examples of CreateGeomResults.

You can also use the Analysis Manager to perform 'SurfacePatches' analysis.  This will only work for 'regular' Geoms (not MeshGeoms), and it will output a structured surface patch corresponding to the wireframe on screen.

However there are some differences between this and CreateGeomResults.  First, in addition to the surface points, normal vectors are also output -- these are actually normal vectors based on the analytic Bezier surfaces underlying the representation.  Of course, at a sharp corner (think a wingtip), a point has a single value, but the normal vector has multiple values.  To handle this, SurfacePatches actually splits the surfaces along the feature lines in OpenVSP and then will output different normal vectors for each patch.

This is the approach used by OpenVSP's own OpenGL drawing to get good shading around corners where there are multiple normal vectors.

Rob

 

Daniel Ingraham

unread,
Sep 14, 2022, 9:09:04 AM9/14/22
to OpenVSP
Great, I'll try this soon. Thanks again!

Daniel

Reply all
Reply to author
Forward
0 new messages