General API Utility Functions

This group of functions is provided for general API utilities, such as printing to stdout, performing basic math functions, and identifying basic OpenVSP information.

VSPCheckSetup()

Check if OpenVSP has been initialized successfully.

VSPRenew()

Clear and reinitialize OpenVSP to all default settings

Print(*args)

Overload 1:

Min(x, y)

Get the smaller of two values.

Max(x, y)

Get the larger of two values.

Rad2Deg(r)

Convert an angle from radians to degrees.

Deg2Rad(d)

Convert an angle from degrees to radians.

GetVSPVersion()

Get the version of the OpenVSP instance currently running

GetVSPVersionMajor()

Get the major version of the OpenVSP instance currently running as an integer

GetVSPVersionMinor()

Get the minor version of the OpenVSP instance currently running as an integer

GetVSPVersionChange()

Get the change version of the OpenVSP instance currently running as an integer

GetVSPExePath()

Get the path to the OpenVSP executable.

SetVSPAEROPath(path)

Set the path to the VSPAERO executables (Solver, Viewer, and Slicer).

GetVSPAEROPath()

Get the path that OpenVSP will use to look for all VSPAERO executables (Solver, Slicer, and Viewer) when attempting to execute VSPAERO.

CheckForVSPAERO(path)

Check if all VSPAERO executables (Solver, Viewer, and Slicer) are in a given directory.

SetVSPHelpPath(path)

Set the path to the OpenVSP help files.

GetVSPHelpPath()

Get the path that OpenVSP will use to look for all OpenVSP help files.

CheckForVSPHelp(path)

Check if all OpenVSP help files are in a given directory.

Details

openvsp.VSPCheckSetup()[source]

Check if OpenVSP has been initialized successfully. If not, the OpenVSP instance will be exited. This call should be placed at the beginning of all API scripts.

VSPCheckSetup()

# A failed setup exits OpenVSP outright, so reaching this point is most of
# the test.  Confirm the model is actually usable.
type_array = GetGeomTypes()

assert len( type_array ) > 0, "VSPCheckSetup did not leave a usable model"

# Continue to do things...
openvsp.VSPRenew()[source]

Clear and reinitialize OpenVSP to all default settings

#==== Add Pod Geometry ====//
pod_id = AddGeom( "POD" )

SetParmVal( pod_id, "Y_Rel_Location", "XForm", 2.0 )

VSPRenew()

if  len(FindGeoms()) != 0 :
    print( "ERROR: VSPRenew" )
    assert False, "ERROR: VSPRenew"
openvsp.Print(*args)[source]

Overload 1:

Print a string to stdout. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( "Hello from the OpenVSP API" )

See also: Min, Max, Rad2Deg, Deg2Rad :param [in]: data string Text to print :param [in]: new_line bool Follow the text with a newline


Overload 2:

Print a vec3d to stdout, as its three coordinates. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( vec3d( 1.0, 2.0, 3.0 ) )

See also: Print :param [in]: data vec3d Point to print :param [in]: new_line bool Follow the point with a newline


Overload 3:

Print a vec3d to stdout, as its three coordinates. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( vec3d( 1.0, 2.0, 3.0 ) )

See also: Print :param [in]: data vec3d Point to print :param [in]: new_line bool Follow the point with a newline


Overload 4:

Print a double to stdout. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( 3.14159 )

See also: Print :param [in]: data double Value to print :param [in]: new_line bool Follow the value with a newline


Overload 5:

Print a double to stdout. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( 3.14159 )

See also: Print :param [in]: data double Value to print :param [in]: new_line bool Follow the value with a newline


Overload 6:

Print an integer to stdout. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( 42 )

See also: Print :param [in]: data int Value to print :param [in]: new_line bool Follow the value with a newline


Overload 7:

Print an integer to stdout. Print to stdout. Writes the value and, unless asked not to, a newline; there is nothing to check in an example beyond the call itself.

Print( 42 )

See also: Print :param [in]: data int Value to print :param [in]: new_line bool Follow the value with a newline

openvsp.Min(x, y)[source]

Get the smaller of two values.

assert abs( Min( 2.0, 5.0 ) - 2.0 ) < 1e-12, "Min did not return the smaller value"

assert abs( Min( 5.0, 2.0 ) - 2.0 ) < 1e-12, "Min depends on the order of its arguments"

See also: Max :param [in]: x double First value :param [in]: y double Second value :rtype: float :return: double The smaller of the two

openvsp.Max(x, y)[source]

Get the larger of two values.

assert abs( Max( 2.0, 5.0 ) - 5.0 ) < 1e-12, "Max did not return the larger value"

assert abs( Max( 5.0, 2.0 ) - 5.0 ) < 1e-12, "Max depends on the order of its arguments"

See also: Min :param [in]: x double First value :param [in]: y double Second value :rtype: float :return: double The larger of the two

openvsp.Rad2Deg(r)[source]

Convert an angle from radians to degrees.

import math

assert abs( Rad2Deg( math.pi ) - 180.0 ) < 1e-9, "Rad2Deg did not convert half a turn to 180 degrees"

See also: Deg2Rad :param [in]: r double Angle in radians :rtype: float :return: double Angle in degrees

openvsp.Deg2Rad(d)[source]

Convert an angle from degrees to radians.

import math

assert abs( Deg2Rad( 180.0 ) - math.pi ) < 1e-9, "Deg2Rad did not convert 180 degrees to half a turn"

See also: Rad2Deg :param [in]: d double Angle in degrees :rtype: float :return: double Angle in radians

openvsp.GetVSPVersion()[source]

Get the version of the OpenVSP instance currently running

print( "The current OpenVSP version is: ", False )

ver = GetVSPVersion()

print( ver )

# The string form has to agree with the numeric accessors.
num = f"{GetVSPVersionMajor()}.{GetVSPVersionMinor()}.{GetVSPVersionChange()}"

assert num in ver, "GetVSPVersion does not contain " + num
Return type:

string

Returns:

string OpenVSP version string (i.e. “OpenVSP 3.17.1”)

openvsp.GetVSPVersionMajor()[source]

Get the major version of the OpenVSP instance currently running as an integer

print( "The current OpenVSP version is: ", False )

major = GetVSPVersionMajor()
minor = GetVSPVersionMinor()
change = GetVSPVersionChange()

print( f"{major}.{minor}.{change}" )

# OpenVSP 3 and later.  Negative pieces would mean the version was never
# filled in.
assert major >= 3 and minor >= 0 and change >= 0, "implausible version number"

# The pieces have to add back up to the string form.
num = f"{major}.{minor}.{change}"

assert num in GetVSPVersion(), "version pieces disagree with GetVSPVersion"
Return type:

int

Returns:

int OpenVSP major version number (i.e. 3 in 3.X.Y)

openvsp.GetVSPVersionMinor()[source]

Get the minor version of the OpenVSP instance currently running as an integer

print( "The current OpenVSP version is: ", False )

major = GetVSPVersionMajor()
minor = GetVSPVersionMinor()
change = GetVSPVersionChange()

print( f"{major}.{minor}.{change}" )

# OpenVSP 3 and later.  Negative pieces would mean the version was never
# filled in.
assert major >= 3 and minor >= 0 and change >= 0, "implausible version number"

# The pieces have to add back up to the string form.
num = f"{major}.{minor}.{change}"

assert num in GetVSPVersion(), "version pieces disagree with GetVSPVersion"
Return type:

int

Returns:

int OpenVSP minor version number (i.e. X in 3.X.Y)

openvsp.GetVSPVersionChange()[source]

Get the change version of the OpenVSP instance currently running as an integer

print( "The current OpenVSP version is: ", False )

major = GetVSPVersionMajor()
minor = GetVSPVersionMinor()
change = GetVSPVersionChange()

print( f"{major}.{minor}.{change}" )

# OpenVSP 3 and later.  Negative pieces would mean the version was never
# filled in.
assert major >= 3 and minor >= 0 and change >= 0, "implausible version number"

# The pieces have to add back up to the string form.
num = f"{major}.{minor}.{change}"

assert num in GetVSPVersion(), "version pieces disagree with GetVSPVersion"
Return type:

int

Returns:

int OpenVSP change version number (i.e. Y in 3.X.Y)

openvsp.GetVSPExePath()[source]

Get the path to the OpenVSP executable. OpenVSP will assume that the VSPAERO, VSPSLICER, and VSPVIEWER are in the same directory unless instructed otherwise.

print( "The current VSP executable path is: ", False )

exe_path = GetVSPExePath()

print( exe_path )

assert len( exe_path ) > 0, "GetVSPExePath returned an empty path"

See also: SetVSPAEROPath, CheckForVSPAERO, GetVSPAEROPath :rtype: string :return: string Path to the OpenVSP executable

openvsp.SetVSPAEROPath(path)[source]

Set the path to the VSPAERO executables (Solver, Viewer, and Slicer). By default, OpenVSP will assume that the VSPAERO executables are in the same directory as the VSP executable. However, this may need to be changed when using certain API languages like MATLAB and Python. For example, Python may treat the location of the Python executable as the VSP executable path, so either the VSPAERO executable needs to be moved to the same directory or this function can be called to tell Python where to look for VSPAERO.

orig_path = GetVSPAEROPath()

if  not CheckForVSPAERO( GetVSPExePath() ) :
    vspaero_path = "C:/Users/example_user/Documents/OpenVSP_3.4.5"
    SetVSPAEROPath( vspaero_path )

# A directory with no VSPAERO in it has to be rejected, and rejecting it
# must leave the stored path alone.
assert not SetVSPAEROPath( "/no/such/directory/anywhere" ), "SetVSPAEROPath accepted a nonexistent directory"

assert GetVSPAEROPath() == orig_path, "a rejected SetVSPAEROPath changed the stored path"

See also: GetVSPExePath, CheckForVSPAERO, GetVSPAEROPath :param [in]: path string Absolute path to directory containing VSPAERO executable :rtype: boolean :return: bool Flag that indicates whether or not the path was set correctly

openvsp.GetVSPAEROPath()[source]

Get the path that OpenVSP will use to look for all VSPAERO executables (Solver, Slicer, and Viewer) when attempting to execute VSPAERO. If the VSPAERO executables are not in this location, they must either be copied there or the VSPAERO path must be set using SetVSPAEROPath.

if  not CheckForVSPAERO( GetVSPAEROPath() ) :
    print( "VSPAERO is not where OpenVSP thinks it is. I should move the VSPAERO executable or call SetVSPAEROPath." )

assert len( GetVSPAEROPath() ) > 0, "GetVSPAEROPath returned an empty path"

See also: GetVSPExePath, CheckForVSPAERO, SetVSPAEROPath :rtype: string :return: string Path OpenVSP will look for VSPAERO

openvsp.CheckForVSPAERO(path)[source]

Check if all VSPAERO executables (Solver, Viewer, and Slicer) are in a given directory. Note that this function will return false if only one or two VSPAERO executables are found. An error message will indicate the executables that are missing. This may be acceptable, as only the Solver is needed in all cases. The Viewer and Slicer may not be needed.

vspaero_path = "C:/Users/example_user/Documents/OpenVSP_3.4.5"

if  CheckForVSPAERO( vspaero_path ) :
    SetVSPAEROPath( vspaero_path )

# A directory that cannot exist must not report VSPAERO in it.
assert not CheckForVSPAERO( "/no/such/directory/anywhere" ), "CheckForVSPAERO found VSPAERO in a nonexistent directory"

See also: GetVSPExePath, GetVSPAEROPath, SetVSPAEROPath :param [in]: path string Absolute path to check for VSPAERO executables :rtype: boolean :return: bool Flag that indicates if all VSPAERO executables are found or not

openvsp.SetVSPHelpPath(path)[source]

Set the path to the OpenVSP help files. By default, OpenVSP will assume that the OpenVSP help directory is in the same directory as the VSP executable. However, this may need to be changed when using certain API languages like MATLAB and Python. For example, Python may treat the location of the Python executable as the VSP executable path, so either the VSPAERO executable needs to be moved to the same directory or this function can be called to tell Python where to look for help.

orig_path = GetVSPHelpPath()

if  not CheckForVSPHelp( GetVSPExePath() ) :
    vsphelp_path = "C:/Users/example_user/Documents/OpenVSP_3.4.5/help"
    SetVSPHelpPath( vsphelp_path )

# A directory with no help files in it has to be rejected, and rejecting it
# must leave the stored path alone.
assert not SetVSPHelpPath( "/no/such/directory/anywhere" ), "SetVSPHelpPath accepted a nonexistent directory"

assert GetVSPHelpPath() == orig_path, "a rejected SetVSPHelpPath changed the stored path"

See also: GetVSPExePath, CheckForVSPHelp, GetVSPHelpPath :param [in]: path string Absolute path to directory containing OpenVSP help files :rtype: boolean :return: bool Flag that indicates whether or not the path was set correctly

openvsp.GetVSPHelpPath()[source]

Get the path that OpenVSP will use to look for all OpenVSP help files. If the OpenVSP help files are not in this location, they must either be copied there or the VSPHelp path must be set using SetVSPHelpPath.

if  not CheckForVSPHelp( GetVSPHelpPath() ) :
    print( "OpenVSP help is not where OpenVSP thinks it is. I should move the help files or call SetVSPHelpPath." )

assert len( GetVSPHelpPath() ) > 0, "GetVSPHelpPath returned an empty path"

See also: GetVSPExePath, CheckForVSPHelp, SetVSPHelpPath :rtype: string :return: string Path OpenVSP will look for help files

openvsp.CheckForVSPHelp(path)[source]

Check if all OpenVSP help files are in a given directory.

vsphelp_path = "C:/Users/example_user/Documents/OpenVSP_3.4.5/help"

if  CheckForVSPHelp( vsphelp_path ) :
    SetVSPHelpPath( vsphelp_path )

# A directory that cannot exist must not report help files in it.
assert not CheckForVSPHelp( "/no/such/directory/anywhere" ), "CheckForVSPHelp found help in a nonexistent directory"

See also: GetVSPExePath, GetVSPAEROPath, SetVSPHelpPath :param [in]: path string Absolute path to check for VSPAERO executables :rtype: boolean :return: bool Flag that indicates if OpenVSP help files are found or not