Fit Model Functions

This group of functions supports the Fit Model Tool, which adjusts a model until its surfaces pass through a set of known points. Each point to match is set up as a target point: a point in space paired with the surface of a Geom, either pinned to a surface coordinate or free to slide along the surface. One or more Parms are then nominated as variables. Together these define a least squares problem, which is solved with a Levenberg-Marquardt algorithm where the free surface coordinates and the nominated Parms are the degrees of freedom and every target point contributes three residuals. Unlike the GUI, the API takes target points directly as coordinates rather than through a point cloud Geom and mouse selection.

ResetFitModel()

Clear the Fit Model Tool, removing every target point and every variable.

AddFitModelTargetPt(*args)

Add a target point to the Fit Model Tool.

AddFitModelTargetPtFixedU(geom_id, ...)

Add one target point held at a U surface coordinate and free to slide in W.

AddFitModelTargetPtFixedW(geom_id, ...)

Add one target point held at a W surface coordinate and free to slide in U.

AddFitModelTargetPtFixedUW(geom_id, ...)

Add one target point pinned to a surface coordinate, free in neither direction.

AddFitModelTargetPts(geom_id, surf_indx, pt_vec)

Add a group of target points to the Fit Model Tool, all matched to the same Geom, each free to slide anywhere on the surface.

AddFitModelTargetPtsFixedU(geom_id, ...)

Add a group of target points held at one U surface coordinate and free to slide in W.

AddFitModelTargetPtsFixedUs(geom_id, ...)

Add a group of target points, each held at its own U surface coordinate and free to slide in W.

AddFitModelTargetPtsFixedW(geom_id, ...)

Add a group of target points held at one W surface coordinate and free to slide in U.

AddFitModelTargetPtsFixedWs(geom_id, ...)

Add a group of target points, each held at its own W surface coordinate and free to slide in U.

AddFitModelTargetPtsFixedUW(geom_id, ...)

Add a group of target points all held at one surface coordinate, free in neither direction.

AddFitModelTargetPtsFixedUWs(geom_id, ...)

Add a group of target points, each pinned to its own surface coordinate and free in neither direction.

DelFitModelTargetPt(index)

Delete one target point from the Fit Model Tool.

DelAllFitModelTargetPts()

Delete every target point from the Fit Model Tool, leaving the variables alone.

SortFitModelTargetPtsByDist()

Reorder the target points worst fit first, by descending distance from each point to the surface it is matched to.

MoveFitModelTargetPt(index, reorder_type)

Move one target point within the Fit Model Tool's list, and return where it ended up.

GetNumFitModelTargetPts()

Get the number of target points held by the Fit Model Tool.

GetFitModelTargetPt(index)

Get the point a target point is trying to match.

SetFitModelTargetPt(index, pt)

Move the point a target point is trying to match.

GetFitModelTargetPtGeom(index)

Get the Geom a target point is matched to.

SetFitModelTargetPtGeom(index, geom_id)

Match a target point to a different Geom.

GetFitModelTargetPtSurfIndx(index)

Get the surface of the matched Geom a target point is paired with.

SetFitModelTargetPtSurfIndx(index, surf_indx)

Pair a target point with a different surface of the Geom it is already matched to.

GetFitModelTargetPtU(index)

Get the U surface coordinate of a target point.

GetFitModelTargetPtW(index)

Get the W surface coordinate of a target point.

GetFitModelTargetPtDist(index)

Get the distance from a target point to the surface point it is matched to.

SetFitModelTargetPtUW(index, u, w)

Set the surface coordinate of a target point.

GetFitModelTargetPtUType(index)

Get whether the U direction of a target point is pinned or free.

SetFitModelTargetPtUType(index, u_type)

Pin or free the U direction of a target point.

GetFitModelTargetPtWType(index)

Get whether the W direction of a target point is pinned or free.

SetFitModelTargetPtWType(index, w_type)

Pin or free the W direction of a target point.

GetFitModelTargetPtSurfPt(index)

Get the point currently on the surface at a target point's surface coordinate.

AddFitModelVar(parm_id)

Nominate a Parm as a variable for the Fit Model Tool to adjust.

DelFitModelVar(parm_id)

Withdraw a Parm from the Fit Model Tool's variables.

DelAllFitModelVars()

Withdraw every Parm from the Fit Model Tool's variables, leaving the target points alone.

GetNumFitModelVars()

Get the number of Parms nominated as Fit Model Tool variables.

GetFitModelVar(index)

Get the Parm ID of one Fit Model Tool variable.

GetFitModelVarVec()

Get the Parm IDs of every Fit Model Tool variable.

SearchFitModelTargetUW()

Move every free target point to the closest point on its surface, searching the whole surface rather than working from where the point currently sits.

RefineFitModelTargetUW()

Move every free target point to the closest point on its surface, starting from where the point currently sits.

UpdateFitModelDist()

Recompute and return how far the model is from the target points.

GetFitModelDist()

Get the distance measure last computed, without recomputing it.

GetNumFitModelOptVars()

Get the number of degrees of freedom the optimization problem has: one for each variable, plus one for each free direction of each target point.

OptimizeFitModel()

Adjust the variables, and any free target point surface coordinates, until the surfaces pass as close as they can to the target points.

CanUndoFitModel()

Check whether the last Fit Model operation can be undone.

UndoFitModel()

Undo the last Fit Model operation, putting back the Parm values and the free surface coordinates of the target points as they were before OptimizeFitModel, SearchFitModelTargetUW or RefineFitModelTargetUW was run.

SaveFitModelFile(file_name)

Write the Fit Model Tool's target points and variables to a .fit file.

LoadFitModelFile(file_name)

Read target points and variables from a .fit file, adding them to whatever the Fit Model Tool already holds.

Details

openvsp.ResetFitModel()[source]

Clear the Fit Model Tool, removing every target point and every variable.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, vec3d( 3.0, 0.0, 0.0 ) )

ResetFitModel()

assert GetNumFitModelTargetPts() == 0, "ResetFitModel left target points behind"

See also: DelAllFitModelTargetPts, DelAllFitModelVars

openvsp.AddFitModelTargetPt(*args)[source]

Add a target point to the Fit Model Tool. The point is paired with the first surface of the given Geom. Each direction may be pinned to the supplied surface coordinate ( FIT_MODEL_FIXED ) or left free to slide along the surface ( FIT_MODEL_FREE ). The supplied coordinate is used for a pinned direction; a free one is searched onto the nearest point of the surface as the point is added, so what is passed for it does not matter.

Called with a Geom and a point alone this leaves both directions free, matching AddFitModelTargetPts. It is the general form: use it to walk a loop of points that each want their own pinned or free directions and their own coordinates. Where every point in a group wants the same treatment, the named forms say so more plainly.

pid = AddGeom( "POD" )

Update()

pnt = CompPnt01( pid, 0, 0.5, 0.0 )

index = AddFitModelTargetPt( pid, 0, pnt, FIT_MODEL_FREE, FIT_MODEL_FREE )

assert index == 0, "AddFitModelTargetPt did not return the first index"

assert GetNumFitModelTargetPts() == 1, "AddFitModelTargetPt did not add a point"

See also: FIT_MODEL_TARGET_TYPE, AddFitModelTargetPtFixedU, AddFitModelTargetPtFixedW, AddFitModelTargetPtFixedUW, AddFitModelTargetPts :param [in]: geom_id string Geom ID of the surface the point is matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt vec3d Point to be matched, in model coordinates :param [in]: u_type int Fit model target type enum for the U direction (i.e. FIT_MODEL_FREE) :param [in]: w_type int Fit model target type enum for the W direction (i.e. FIT_MODEL_FREE) :param [in]: u double Starting U surface coordinate in [0, 1] :param [in]: w double Starting W surface coordinate in [0, 1] :rtype: int :return: int Index of the new target point

openvsp.AddFitModelTargetPtFixedU(geom_id, surf_indx, pt, u)[source]

Add one target point held at a U surface coordinate and free to slide in W. The single point counterpart of AddFitModelTargetPtsFixedU. The W of the point is searched onto the surface as it is added.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPtFixedU( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), 0.5 )

assert GetFitModelTargetPtUType( 0 ) == FIT_MODEL_FIXED, "AddFitModelTargetPtFixedU did not pin U"

assert abs( GetFitModelTargetPtU( 0 ) - 0.5 ) < 1e-6, "AddFitModelTargetPtFixedU did not use the given U"

assert UpdateFitModelDist() < 1e-4, "AddFitModelTargetPtFixedU did not place the point on the surface"

See also: AddFitModelTargetPtsFixedU, AddFitModelTargetPtFixedW, AddFitModelTargetPt :param [in]: geom_id string Geom ID of the surface the point is matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt vec3d Point to be matched, in model coordinates :param [in]: u double U surface coordinate in [0, 1] to hold the point at :rtype: int :return: int Index of the new target point

openvsp.AddFitModelTargetPtFixedW(geom_id, surf_indx, pt, w)[source]

Add one target point held at a W surface coordinate and free to slide in U. The single point counterpart of AddFitModelTargetPtsFixedW. The U of the point is searched onto the surface as it is added.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPtFixedW( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), 0.25 )

assert GetFitModelTargetPtWType( 0 ) == FIT_MODEL_FIXED, "AddFitModelTargetPtFixedW did not pin W"

assert abs( GetFitModelTargetPtW( 0 ) - 0.25 ) < 1e-6, "AddFitModelTargetPtFixedW did not use the given W"

assert UpdateFitModelDist() < 1e-4, "AddFitModelTargetPtFixedW did not place the point on the surface"

See also: AddFitModelTargetPtsFixedW, AddFitModelTargetPtFixedU, AddFitModelTargetPt :param [in]: geom_id string Geom ID of the surface the point is matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt vec3d Point to be matched, in model coordinates :param [in]: w double W surface coordinate in [0, 1] to hold the point at :rtype: int :return: int Index of the new target point

openvsp.AddFitModelTargetPtFixedUW(geom_id, surf_indx, pt, u, w)[source]

Add one target point pinned to a surface coordinate, free in neither direction. The single point counterpart of AddFitModelTargetPtsFixedUW. Nothing is searched; the point contributes no degrees of freedom, so the fit has only the model’s own Parms to work with.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPtFixedUW( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), 0.5, 0.25 )

assert GetNumFitModelOptVars() == 0, "AddFitModelTargetPtFixedUW left a direction free"

assert UpdateFitModelDist() < 1e-6, "AddFitModelTargetPtFixedUW did not land on the given coordinate"

See also: AddFitModelTargetPtsFixedUW, AddFitModelTargetPt :param [in]: geom_id string Geom ID of the surface the point is matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt vec3d Point to be matched, in model coordinates :param [in]: u double U surface coordinate in [0, 1] to hold the point at :param [in]: w double W surface coordinate in [0, 1] to hold the point at :rtype: int :return: int Index of the new target point

openvsp.AddFitModelTargetPts(geom_id, surf_indx, pt_vec)[source]

Add a group of target points to the Fit Model Tool, all matched to the same Geom, each free to slide anywhere on the surface. This is the API’s replacement for selecting points of a point cloud with the mouse. Every point is placed on the nearest point of the surface as it is added, searching the whole surface, so no starting coordinate is asked for: a caller is unlikely to have a useful guess for a free coordinate. Where the topology does tell you where a point belongs, use one of the fixed variants instead.

pid = AddGeom( "POD" )

Update()

pts = []

pts.append( CompPnt01( pid, 0, 0.25, 0.0 ) )
pts.append( CompPnt01( pid, 0, 0.50, 0.0 ) )
pts.append( CompPnt01( pid, 0, 0.75, 0.0 ) )

AddFitModelTargetPts( pid, 0, pts )

assert GetNumFitModelTargetPts() == 3, "AddFitModelTargetPts did not add three points"

assert UpdateFitModelDist() < 1e-4, "AddFitModelTargetPts did not place the points on the surface"

See also: AddFitModelTargetPtsFixedU, AddFitModelTargetPtsFixedW, AddFitModelTargetPtsFixedUW, SearchFitModelTargetUW :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates

openvsp.AddFitModelTargetPtsFixedU(geom_id, surf_indx, pt_vec, u)[source]

Add a group of target points held at one U surface coordinate and free to slide in W. Use this where the topology says which station the points belong to but not where around it, such as points measured around one fuselage frame. The W of each point is searched onto the surface as it is added.

pid = AddGeom( "POD" )

Update()

pts = []

pts.append( CompPnt01( pid, 0, 0.5, 0.10 ) )
pts.append( CompPnt01( pid, 0, 0.5, 0.35 ) )
pts.append( CompPnt01( pid, 0, 0.5, 0.60 ) )

AddFitModelTargetPtsFixedU( pid, 0, pts, 0.5 )

assert GetFitModelTargetPtUType( 0 ) == FIT_MODEL_FIXED, "AddFitModelTargetPtsFixedU did not pin U"

assert abs( GetFitModelTargetPtU( 0 ) - 0.5 ) < 1e-6, "AddFitModelTargetPtsFixedU did not use the given U"

See also: AddFitModelTargetPtsFixedUs, AddFitModelTargetPtsFixedW, AddFitModelTargetPts :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates :param [in]: u double U surface coordinate in [0, 1] to hold every point at

openvsp.AddFitModelTargetPtsFixedUs(geom_id, surf_indx, pt_vec, u_vec)[source]

Add a group of target points, each held at its own U surface coordinate and free to slide in W. The two vectors are paired by index and must be the same length. The W of each point is searched onto the surface as it is added.

pid = AddGeom( "POD" )

Update()

pts = []
us = []

for u in [ 0.25, 0.50, 0.75 ]:
    pts.append( CompPnt01( pid, 0, u, 0.1 ) )
    us.append( u )

AddFitModelTargetPtsFixedUs( pid, 0, pts, us )

assert abs( GetFitModelTargetPtU( 2 ) - 0.75 ) < 1e-6, "AddFitModelTargetPtsFixedUs did not use the given U values"

See also: AddFitModelTargetPtsFixedU, AddFitModelTargetPtsFixedWs :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates :param [in]: u_vec vector<double> U surface coordinate in [0, 1] for each point, same length as pt_vec

openvsp.AddFitModelTargetPtsFixedW(geom_id, surf_indx, pt_vec, w)[source]

Add a group of target points held at one W surface coordinate and free to slide in U. Use this where the topology says which line around the section the points belong to but not where along it, such as points measured along a wing’s leading edge. The U of each point is searched onto the surface as it is added.

pid = AddGeom( "POD" )

Update()

pts = []

pts.append( CompPnt01( pid, 0, 0.25, 0.5 ) )
pts.append( CompPnt01( pid, 0, 0.50, 0.5 ) )
pts.append( CompPnt01( pid, 0, 0.75, 0.5 ) )

AddFitModelTargetPtsFixedW( pid, 0, pts, 0.5 )

assert GetFitModelTargetPtWType( 0 ) == FIT_MODEL_FIXED, "AddFitModelTargetPtsFixedW did not pin W"

assert abs( GetFitModelTargetPtW( 0 ) - 0.5 ) < 1e-6, "AddFitModelTargetPtsFixedW did not use the given W"

See also: AddFitModelTargetPtsFixedWs, AddFitModelTargetPtsFixedU, AddFitModelTargetPts :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates :param [in]: w double W surface coordinate in [0, 1] to hold every point at

openvsp.AddFitModelTargetPtsFixedWs(geom_id, surf_indx, pt_vec, w_vec)[source]

Add a group of target points, each held at its own W surface coordinate and free to slide in U. The two vectors are paired by index and must be the same length. The U of each point is searched onto the surface as it is added.

pid = AddGeom( "POD" )

Update()

pts = []
ws = []

for w in [ 0.10, 0.35, 0.60 ]:
    pts.append( CompPnt01( pid, 0, 0.3, w ) )
    ws.append( w )

AddFitModelTargetPtsFixedWs( pid, 0, pts, ws )

assert abs( GetFitModelTargetPtW( 2 ) - 0.60 ) < 1e-6, "AddFitModelTargetPtsFixedWs did not use the given W values"

See also: AddFitModelTargetPtsFixedW, AddFitModelTargetPtsFixedUs :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates :param [in]: w_vec vector<double> W surface coordinate in [0, 1] for each point, same length as pt_vec

openvsp.AddFitModelTargetPtsFixedUW(geom_id, surf_indx, pt_vec, u, w)[source]

Add a group of target points all held at one surface coordinate, free in neither direction. Every point is pinned to the same place on the surface, which suits repeated measurements of one identifiable feature. To pin each point to its own coordinate, use AddFitModelTargetPtsFixedUWs.

pid = AddGeom( "POD" )

Update()

pts = []

pts.append( CompPnt01( pid, 0, 0.5, 0.25 ) )

AddFitModelTargetPtsFixedUW( pid, 0, pts, 0.5, 0.25 )

assert GetFitModelTargetPtUType( 0 ) == FIT_MODEL_FIXED, "AddFitModelTargetPtsFixedUW did not pin U"

assert GetFitModelTargetPtWType( 0 ) == FIT_MODEL_FIXED, "AddFitModelTargetPtsFixedUW did not pin W"

assert UpdateFitModelDist() < 1e-6, "AddFitModelTargetPtsFixedUW did not land on the given coordinate"

See also: AddFitModelTargetPtsFixedUWs, AddFitModelTargetPt :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates :param [in]: u double U surface coordinate in [0, 1] to hold every point at :param [in]: w double W surface coordinate in [0, 1] to hold every point at

openvsp.AddFitModelTargetPtsFixedUWs(geom_id, surf_indx, pt_vec, u_vec, w_vec)[source]

Add a group of target points, each pinned to its own surface coordinate and free in neither direction. The three vectors are paired by index and must all be the same length. Use this where every point has been identified on the surface already, so the fit has only the model’s own Parms to work with.

pid = AddGeom( "POD" )

Update()

pts = []
us = []
ws = []

for u, w in [ ( 0.25, 0.1 ), ( 0.50, 0.4 ), ( 0.75, 0.7 ) ]:
    pts.append( CompPnt01( pid, 0, u, w ) )
    us.append( u )
    ws.append( w )

AddFitModelTargetPtsFixedUWs( pid, 0, pts, us, ws )

assert GetNumFitModelOptVars() == 0, "AddFitModelTargetPtsFixedUWs left a direction free"

assert UpdateFitModelDist() < 1e-6, "AddFitModelTargetPtsFixedUWs did not land on the given coordinates"

See also: AddFitModelTargetPtsFixedUW, AddFitModelTargetPtsFixedUs, AddFitModelTargetPtsFixedWs :param [in]: geom_id string Geom ID of the surface the points are matched to :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: pt_vec vector<vec3d> Points to be matched, in model coordinates :param [in]: u_vec vector<double> U surface coordinate in [0, 1] for each point, same length as pt_vec :param [in]: w_vec vector<double> W surface coordinate in [0, 1] for each point, same length as pt_vec

openvsp.DelFitModelTargetPt(index)[source]

Delete one target point from the Fit Model Tool. The points after it move down one index.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.25, 0.0 ) )
AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.75, 0.0 ) )

DelFitModelTargetPt( 0 )

assert GetNumFitModelTargetPts() == 1, "DelFitModelTargetPt did not remove a point"

See also: DelAllFitModelTargetPts :param [in]: index int Target point index

openvsp.DelAllFitModelTargetPts()[source]

Delete every target point from the Fit Model Tool, leaving the variables alone.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

DelAllFitModelTargetPts()

assert GetNumFitModelTargetPts() == 0, "DelAllFitModelTargetPts left points behind"

See also: DelFitModelTargetPt, ResetFitModel

openvsp.SortFitModelTargetPtsByDist()[source]

Reorder the target points worst fit first, by descending distance from each point to the surface it is matched to. The distances are recomputed before sorting, so the order describes the model as it stands. Target points are addressed by index, so this renumbers them – an index held across the call names a different point afterwards.

pid = AddGeom( "POD" )

Update()

near_pnt = CompPnt01( pid, 0, 0.5, 0.25 )
far_pnt = vec3d( near_pnt.x(), near_pnt.y(), near_pnt.z() + 1.0 )

AddFitModelTargetPtFixedUW( pid, 0, near_pnt, 0.5, 0.25 )
AddFitModelTargetPtFixedUW( pid, 0, far_pnt, 0.5, 0.25 )

SortFitModelTargetPtsByDist()

assert abs( GetFitModelTargetPt( 0 ).z() - far_pnt.z() ) < 1e-6, "SortFitModelTargetPtsByDist did not put the worst fit first"

See also: UpdateFitModelDist, GetFitModelTargetPt

openvsp.MoveFitModelTargetPt(index, reorder_type)[source]

Move one target point within the Fit Model Tool’s list, and return where it ended up. Target points are addressed by index, so this renumbers them – an index held across the call names a different point afterwards. Order does not change the fit; it is the order the points are listed and stepped through in.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.25, 0.0 ) )
AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.50, 0.0 ) )

last_pnt = CompPnt01( pid, 0, 0.75, 0.0 )

AddFitModelTargetPt( pid, 0, last_pnt )

newindex = MoveFitModelTargetPt( 2, REORDER_MOVE_TOP )

assert newindex == 0, "MoveFitModelTargetPt did not report the point at the top"

assert abs( GetFitModelTargetPt( 0 ).x() - last_pnt.x() ) < 1e-6, "MoveFitModelTargetPt did not move the point to the top"

See also: SortFitModelTargetPtsByDist, GetFitModelTargetPt, REORDER_TYPE :param [in]: index int Index of target point to move :param [in]: reorder_type int Enum specifying reordering type (i.e. REORDER_MOVE_UP, REORDER_MOVE_DOWN, REORDER_MOVE_TOP, REORDER_MOVE_BOTTOM) :rtype: int :return: int Index the target point ended up at

openvsp.GetNumFitModelTargetPts()[source]

Get the number of target points held by the Fit Model Tool.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

assert GetNumFitModelTargetPts() == 1, "GetNumFitModelTargetPts did not count the point"

See also: AddFitModelTargetPt :rtype: int :return: int Number of target points

openvsp.GetFitModelTargetPt(index)[source]

Get the point a target point is trying to match. This is the point supplied when it was added, not the point currently on the surface; for that, see GetFitModelTargetPtSurfPt.

pid = AddGeom( "POD" )

Update()

pnt = vec3d( 3.0, 1.0, 2.0 )

AddFitModelTargetPt( pid, 0, pnt )

pnt_out = GetFitModelTargetPt( 0 )

assert dist( pnt, pnt_out ) < 1e-6, "GetFitModelTargetPt did not report the point that was set"

See also: SetFitModelTargetPt, GetFitModelTargetPtSurfPt :param [in]: index int Target point index :rtype: vec3d :return: vec3d Point to be matched

openvsp.SetFitModelTargetPt(index, pt)[source]

Move the point a target point is trying to match.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, vec3d( 0.0, 0.0, 0.0 ) )

SetFitModelTargetPt( 0, vec3d( 3.0, 1.0, 2.0 ) )

assert dist( GetFitModelTargetPt( 0 ), vec3d( 3.0, 1.0, 2.0 ) ) < 1e-6, "SetFitModelTargetPt did not take"

See also: GetFitModelTargetPt :param [in]: index int Target point index :param [in]: pt vec3d Point to be matched, in model coordinates

openvsp.GetFitModelTargetPtGeom(index)[source]

Get the Geom a target point is matched to.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

assert GetFitModelTargetPtGeom( 0 ) == pid, "GetFitModelTargetPtGeom did not report the Geom that was set"

See also: SetFitModelTargetPtGeom :param [in]: index int Target point index :rtype: string :return: string Geom ID of the matched surface

openvsp.SetFitModelTargetPtGeom(index, geom_id)[source]

Match a target point to a different Geom.

pid = AddGeom( "POD" )

fid = AddGeom( "FUSELAGE" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

SetFitModelTargetPtGeom( 0, fid )

assert GetFitModelTargetPtGeom( 0 ) == fid, "SetFitModelTargetPtGeom did not take"

See also: GetFitModelTargetPtGeom :param [in]: index int Target point index :param [in]: geom_id string Geom ID of the surface the point is matched to

openvsp.GetFitModelTargetPtSurfIndx(index)[source]

Get the surface of the matched Geom a target point is paired with.

pid = AddGeom( "POD" )

SetParmVal( FindParm( pid, "Sym_Planar_Flag", "Sym" ), SYM_XZ )

Update()

AddFitModelTargetPt( pid, 1, CompPnt01( pid, 1, 0.5, 0.25 ) )

assert GetFitModelTargetPtSurfIndx( 0 ) == 1, "GetFitModelTargetPtSurfIndx did not report the surface that was set"

assert UpdateFitModelDist() < 1e-4, "target point did not land on the second surface"

See also: SetFitModelTargetPtSurfIndx, GetFitModelTargetPtGeom :param [in]: index int Target point index :rtype: int :return: int Index of the matched surface of the Geom

openvsp.SetFitModelTargetPtSurfIndx(index, surf_indx)[source]

Pair a target point with a different surface of the Geom it is already matched to. The index must be in range on that Geom. Note that surfaces are numbered by position, so turning symmetry on or off, or changing the number of copies of a Geom, changes which surface an index names.

pid = AddGeom( "POD" )

SetParmVal( FindParm( pid, "Sym_Planar_Flag", "Sym" ), SYM_XZ )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 1, 0.5, 0.25 ) )

SetFitModelTargetPtSurfIndx( 0, 1 )

assert GetFitModelTargetPtSurfIndx( 0 ) == 1, "SetFitModelTargetPtSurfIndx did not take"

SearchFitModelTargetUW()

assert UpdateFitModelDist() < 1e-4, "target point did not land on the second surface"

See also: GetFitModelTargetPtSurfIndx, SetFitModelTargetPtGeom :param [in]: index int Target point index :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1

openvsp.GetFitModelTargetPtU(index)[source]

Get the U surface coordinate of a target point.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), FIT_MODEL_FIXED, FIT_MODEL_FIXED, 0.5, 0.25 )

assert abs( GetFitModelTargetPtU( 0 ) - 0.5 ) < 1e-6, "GetFitModelTargetPtU did not report the U that was set"

See also: GetFitModelTargetPtW, SetFitModelTargetPtUW :param [in]: index int Target point index :rtype: float :return: double U surface coordinate in [0, 1]

openvsp.GetFitModelTargetPtW(index)[source]

Get the W surface coordinate of a target point.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), FIT_MODEL_FIXED, FIT_MODEL_FIXED, 0.5, 0.25 )

assert abs( GetFitModelTargetPtW( 0 ) - 0.25 ) < 1e-6, "GetFitModelTargetPtW did not report the W that was set"

See also: GetFitModelTargetPtU, SetFitModelTargetPtUW :param [in]: index int Target point index :rtype: float :return: double W surface coordinate in [0, 1]

openvsp.GetFitModelTargetPtDist(index)[source]

Get the distance from a target point to the surface point it is matched to.

The Fit Model browser shows this in its Dist column and the API can sort the target points by it, so it was the one quantity a script could order by without being able to read. Meaningful after Update, which is what recomputes it.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), FIT_MODEL_FIXED, FIT_MODEL_FIXED, 0.5, 0.25 )

Update()

assert GetFitModelTargetPtDist( 0 ) < 1e-6, "a target point placed on the surface is not at zero distance"

See also: SortFitModelTargetPtsByDist :param [in]: index int Target point index :rtype: float :return: double Distance from the target point to the surface

openvsp.SetFitModelTargetPtUW(index, u, w)[source]

Set the surface coordinate of a target point. For a fixed direction this is where the point is held; for a free direction it is only where the search starts.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ) )

SetFitModelTargetPtUW( 0, 0.5, 0.25 )

assert abs( GetFitModelTargetPtU( 0 ) - 0.5 ) < 1e-6, "SetFitModelTargetPtUW did not take"

See also: GetFitModelTargetPtU, GetFitModelTargetPtW :param [in]: index int Target point index :param [in]: u double U surface coordinate in [0, 1] :param [in]: w double W surface coordinate in [0, 1]

openvsp.GetFitModelTargetPtUType(index)[source]

Get whether the U direction of a target point is pinned or free.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ), FIT_MODEL_FIXED, FIT_MODEL_FREE )

assert GetFitModelTargetPtUType( 0 ) == FIT_MODEL_FIXED, "GetFitModelTargetPtUType did not report the type that was set"

See also: FIT_MODEL_TARGET_TYPE, SetFitModelTargetPtUType :param [in]: index int Target point index :rtype: int :return: int Fit model target type enum (i.e. FIT_MODEL_FREE)

openvsp.SetFitModelTargetPtUType(index, u_type)[source]

Pin or free the U direction of a target point.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

SetFitModelTargetPtUType( 0, FIT_MODEL_FIXED )

assert GetFitModelTargetPtUType( 0 ) == FIT_MODEL_FIXED, "SetFitModelTargetPtUType did not take"

See also: FIT_MODEL_TARGET_TYPE, GetFitModelTargetPtUType :param [in]: index int Target point index :param [in]: u_type int Fit model target type enum (i.e. FIT_MODEL_FREE)

openvsp.GetFitModelTargetPtWType(index)[source]

Get whether the W direction of a target point is pinned or free.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ), FIT_MODEL_FREE, FIT_MODEL_FIXED )

assert GetFitModelTargetPtWType( 0 ) == FIT_MODEL_FIXED, "GetFitModelTargetPtWType did not report the type that was set"

See also: FIT_MODEL_TARGET_TYPE, SetFitModelTargetPtWType :param [in]: index int Target point index :rtype: int :return: int Fit model target type enum (i.e. FIT_MODEL_FREE)

openvsp.SetFitModelTargetPtWType(index, w_type)[source]

Pin or free the W direction of a target point. W often wraps around the surface, and a free W that has wandered to the seam can leave the optimizer stuck; SearchFitModelTargetUW will lift it off.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

SetFitModelTargetPtWType( 0, FIT_MODEL_FIXED )

assert GetFitModelTargetPtWType( 0 ) == FIT_MODEL_FIXED, "SetFitModelTargetPtWType did not take"

See also: FIT_MODEL_TARGET_TYPE, GetFitModelTargetPtWType, SearchFitModelTargetUW :param [in]: index int Target point index :param [in]: w_type int Fit model target type enum (i.e. FIT_MODEL_FREE)

openvsp.GetFitModelTargetPtSurfPt(index)[source]

Get the point currently on the surface at a target point’s surface coordinate. The distance from here to the target point is what the optimizer is driving to zero.

pid = AddGeom( "POD" )

Update()

pnt = CompPnt01( pid, 0, 0.5, 0.25 )

AddFitModelTargetPt( pid, 0, pnt, FIT_MODEL_FIXED, FIT_MODEL_FIXED, 0.5, 0.25 )

surf_pnt = GetFitModelTargetPtSurfPt( 0 )

assert dist( pnt, surf_pnt ) < 1e-6, "GetFitModelTargetPtSurfPt did not land on the target point"

See also: GetFitModelTargetPt, UpdateFitModelDist :param [in]: index int Target point index :rtype: vec3d :return: vec3d Point on the surface at the target point’s surface coordinate

openvsp.AddFitModelVar(parm_id)[source]

Nominate a Parm as a variable for the Fit Model Tool to adjust. Choosing Parms that are not independent of one another, or that have much the same effect on the surface, can leave the optimizer a very long time in converging. Nominating the same Parm twice does nothing and reports an error.

pid = AddGeom( "POD" )

Update()

length = GetParm( pid, "Length", "Design" )

AddFitModelVar( length )

assert GetNumFitModelVars() == 1, "AddFitModelVar did not add the variable"

See also: DelFitModelVar, OptimizeFitModel :param [in]: parm_id string Parm ID

openvsp.DelFitModelVar(parm_id)[source]

Withdraw a Parm from the Fit Model Tool’s variables.

pid = AddGeom( "POD" )

Update()

length = GetParm( pid, "Length", "Design" )

AddFitModelVar( length )

DelFitModelVar( length )

assert GetNumFitModelVars() == 0, "DelFitModelVar did not remove the variable"

See also: AddFitModelVar, DelAllFitModelVars :param [in]: parm_id string Parm ID

openvsp.DelAllFitModelVars()[source]

Withdraw every Parm from the Fit Model Tool’s variables, leaving the target points alone.

pid = AddGeom( "POD" )

Update()

AddFitModelVar( GetParm( pid, "Length", "Design" ) )

DelAllFitModelVars()

assert GetNumFitModelVars() == 0, "DelAllFitModelVars left variables behind"

See also: DelFitModelVar, ResetFitModel

openvsp.GetNumFitModelVars()[source]

Get the number of Parms nominated as Fit Model Tool variables.

pid = AddGeom( "POD" )

Update()

AddFitModelVar( GetParm( pid, "Length", "Design" ) )

assert GetNumFitModelVars() == 1, "GetNumFitModelVars did not count the variable"

See also: AddFitModelVar :rtype: int :return: int Number of variables

openvsp.GetFitModelVar(index)[source]

Get the Parm ID of one Fit Model Tool variable. The variables are held sorted by name, so this index need not follow the order they were added in.

pid = AddGeom( "POD" )

Update()

length = GetParm( pid, "Length", "Design" )

AddFitModelVar( length )

assert GetFitModelVar( 0 ) == length, "GetFitModelVar did not report the variable that was added"

See also: GetFitModelVarVec :param [in]: index int Variable index :rtype: string :return: string Parm ID

openvsp.GetFitModelVarVec()[source]

Get the Parm IDs of every Fit Model Tool variable.

pid = AddGeom( "POD" )

Update()

AddFitModelVar( GetParm( pid, "Length", "Design" ) )

var_array = GetFitModelVarVec()

assert len( var_array ) == 1, "GetFitModelVarVec did not report the variable"

See also: GetFitModelVar :rtype: std::vector< std::string,std::allocator< std::string > > :return: vector<string> Parm IDs of every variable

openvsp.SearchFitModelTargetUW()[source]

Move every free target point to the closest point on its surface, searching the whole surface rather than working from where the point currently sits. This is slower than RefineFitModelTargetUW but does not depend on a good starting coordinate, so it is what lifts a point off a seam it has become stuck against. Fixed directions are left where they are.

pid = AddGeom( "POD" )

Update()

pnt = CompPnt01( pid, 0, 0.5, 0.25 )

AddFitModelTargetPt( pid, 0, pnt, FIT_MODEL_FREE, FIT_MODEL_FREE )

SearchFitModelTargetUW()

assert UpdateFitModelDist() < 1e-4, "SearchFitModelTargetUW did not find the point on the surface"

See also: RefineFitModelTargetUW, UpdateFitModelDist

openvsp.RefineFitModelTargetUW()[source]

Move every free target point to the closest point on its surface, starting from where the point currently sits. This is faster than SearchFitModelTargetUW but can settle on a nearby answer rather than the best one. Fixed directions are left where they are.

pid = AddGeom( "POD" )

Update()

pnt = CompPnt01( pid, 0, 0.5, 0.25 )

AddFitModelTargetPt( pid, 0, pnt, FIT_MODEL_FREE, FIT_MODEL_FREE, 0.45, 0.25 )

RefineFitModelTargetUW()

assert UpdateFitModelDist() < 1e-4, "RefineFitModelTargetUW did not settle on the point"

See also: SearchFitModelTargetUW, UpdateFitModelDist

openvsp.UpdateFitModelDist()[source]

Recompute and return how far the model is from the target points. The measure is the root mean square of the distance from each target point to the point on its surface. Zero is the wanted answer, so it does not also stand for having nothing to measure; with no target points this reports -1.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), FIT_MODEL_FIXED, FIT_MODEL_FIXED, 0.5, 0.25 )

assert UpdateFitModelDist() < 1e-6, "UpdateFitModelDist did not report a matched point as matched"

See also: GetFitModelDist, OptimizeFitModel :rtype: float :return: double Root mean square distance from the target points to the surfaces, or -1 when there are no target points to measure

openvsp.GetFitModelDist()[source]

Get the distance measure last computed, without recomputing it. Reports -1 if the last computation had no target points to measure.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.25 ), FIT_MODEL_FIXED, FIT_MODEL_FIXED, 0.5, 0.25 )

UpdateFitModelDist()

assert GetFitModelDist() < 1e-6, "GetFitModelDist did not report the distance last computed"

See also: UpdateFitModelDist :rtype: float :return: double Root mean square distance last computed

openvsp.GetNumFitModelOptVars()[source]

Get the number of degrees of freedom the optimization problem has: one for each variable, plus one for each free direction of each target point.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ), FIT_MODEL_FREE, FIT_MODEL_FREE )

AddFitModelVar( GetParm( pid, "Length", "Design" ) )

assert GetNumFitModelOptVars() == 3, "GetNumFitModelOptVars did not count one variable and two free directions"

See also: OptimizeFitModel :rtype: int :return: int Number of degrees of freedom

openvsp.OptimizeFitModel()[source]

Adjust the variables, and any free target point surface coordinates, until the surfaces pass as close as they can to the target points. A Levenberg-Marquardt algorithm solves the least squares problem, with three residuals per target point. Least squares needs at least as many conditions as unknowns, so at least three target points are needed for every three degrees of freedom; GetNumFitModelOptVars counts the latter. The return value is the termination code of the solver: 0 reports that the inputs were not usable, which generally means the variables chosen are not independent or do not move the surface at all.

pid = AddGeom( "POD" )

Update()

length = GetParm( pid, "Length", "Design" )

# Sample points from the pod, then stretch it away from them.
pts = []

pts.append( CompPnt01( pid, 0, 0.25, 0.0 ) )
pts.append( CompPnt01( pid, 0, 0.50, 0.0 ) )
pts.append( CompPnt01( pid, 0, 0.75, 0.0 ) )

len0 = GetParmVal( length )

SetParmVal( length, 1.4 * len0 )

Update()

AddFitModelTargetPts( pid, 0, pts )

AddFitModelVar( length )

OptimizeFitModel()

# Fitting the points back should have recovered the original length.
assert abs( GetParmVal( length ) - len0 ) < 1e-3, "OptimizeFitModel did not recover the original length"

See also: AddFitModelTargetPts, AddFitModelVar, UpdateFitModelDist :rtype: int :return: int Termination code of the least squares solver

openvsp.CanUndoFitModel()[source]

Check whether the last Fit Model operation can be undone. False before anything has been run, after an undo has already been used, and when the variables or target points have changed since – a snapshot describes one arrangement of them and cannot be applied to another.

pid = AddGeom( "POD" )

Update()

assert not CanUndoFitModel(), "CanUndoFitModel is true before anything has been run"

pts = [ CompPnt01( pid, 0, 0.2, 0.3 ), CompPnt01( pid, 0, 0.5, 0.6 ) ]

AddFitModelTargetPts( pid, 0, pts )

AddFitModelVar( GetParm( pid, "Length", "Design" ) )

OptimizeFitModel()

assert CanUndoFitModel(), "CanUndoFitModel is false after a fit"

See also: UndoFitModel, OptimizeFitModel :rtype: boolean :return: bool True if there is something to undo

openvsp.UndoFitModel()[source]

Undo the last Fit Model operation, putting back the Parm values and the free surface coordinates of the target points as they were before OptimizeFitModel, SearchFitModelTargetUW or RefineFitModelTargetUW was run. One level deep: the snapshot is spent once it has been used.

pid = AddGeom( "POD" )

Update()

length = GetParm( pid, "Length", "Design" )

pts = [ CompPnt01( pid, 0, 0.2, 0.3 ), CompPnt01( pid, 0, 0.5, 0.6 ) ]

AddFitModelTargetPts( pid, 0, pts )

AddFitModelVar( length )

SetParmVal( length, 7.0 )
Update()

OptimizeFitModel()

assert UndoFitModel(), "UndoFitModel found nothing to undo"

#==== The Parm is back where it was before the fit ====#
assert abs( GetParmVal( length ) - 7.0 ) < 1e-6, "UndoFitModel did not restore the Parm"

#==== And there is nothing left to undo ====#
assert not UndoFitModel(), "UndoFitModel is repeatable, but it should be one level deep"

See also: CanUndoFitModel, OptimizeFitModel, SearchFitModelTargetUW, RefineFitModelTargetUW :rtype: boolean :return: bool True if a previous state was restored

openvsp.SaveFitModelFile(file_name)[source]

Write the Fit Model Tool’s target points and variables to a .fit file.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

AddFitModelVar( GetParm( pid, "Length", "Design" ) )

SaveFitModelFile( "TestFitModel.fit" )

See also: LoadFitModelFile :param [in]: file_name string Name of the .fit file to write

openvsp.LoadFitModelFile(file_name)[source]

Read target points and variables from a .fit file, adding them to whatever the Fit Model Tool already holds. Call ResetFitModel first to read into an empty tool.

pid = AddGeom( "POD" )

Update()

AddFitModelTargetPt( pid, 0, CompPnt01( pid, 0, 0.5, 0.0 ) )

SaveFitModelFile( "TestFitModel.fit" )

ResetFitModel()

LoadFitModelFile( "TestFitModel.fit" )

assert GetNumFitModelTargetPts() == 1, "LoadFitModelFile did not read the target point back"

See also: SaveFitModelFile, ResetFitModel :param [in]: file_name string Name of the .fit file to read :rtype: int :return: int Zero on success, or a nonzero code describing why the file could not be read