Cancel
Showing results for 
Search instead for 
Did you mean: 

Femap API - Output Set Linear Combination

Creator
Creator

Hello all,

 

I am looking to make a linear combination of two output sets resultinging in a new output set via a Femap macro. What I currently have causes Femap to freeze and become entirely unresponsive.

 

My code:

 

Option Explicit

Sub Main

    Dim App As femap.model
    Set App = feFemap()

    Dim scaleFactorTo As Double
    Dim scaleFactorFrom As Double

    Dim osCombineTo As femap.OutputSet
    Set osCombineTo = App.feOutputSet

    Dim osCombineFrom As femap.OutputSet
    Set osCombineFrom = App.feOutputSet

    Dim osSetCombineTo As Object

    Dim osSetCombineFrom As Object

    Dim usrChoice As femap.zReturnCode

    Dim numCombinationSets As Long
    numCombinationSets = 2
    Dim combinationIDs(1) As Long
    Dim scaleFactors(1) As Double

    'PROCEDURE

    'Ask user for group to combine against
    usrChoice = App.feSelectOutputSets( "Select output sets to combine from", osSetCombineFrom)
     If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    Else
    	If(osSetCombineFrom Is Nothing) Then
	    	Exit Sub
	    Else
	    	If(osSetCombineFrom.Count = 0)Then
	    		Exit Sub
	    	End If
	    End If
    End If


    'Ask user for scale factor to combine against
    usrChoice = App.feGetReal("Scale Factor (Combine From)", -99999999, 999999999, scaleFactorFrom)
    If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    End If

    'Ask user for groups to combine to
    usrChoice = App.feSelectOutputSets( "Select output sets to combine from", osSetCombineTo)
    If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    Else
    	If(osSetCombineTo Is Nothing) Then
	    	Exit Sub
	    Else
	    	If(osSetCombineTo.Count = 0)Then
	    		Exit Sub
	    	End If
	    End If
    End If


    'Ask user for scale factor to combine to
	usrChoice = App.feGetReal("Scale Factor (Combine To)", -99999999, 999999999, scaleFactorTo)
    If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    End If

    'Store scale factors
    scaleFactors(0) = scaleFactorFrom
    scaleFactors(1) = scaleFactorTo

    'For each group to combine against
    While osSetCombineFrom.Next

    	osCombineFrom.Get(osSetCombineFrom.CurrentID )

    	osSetCombineTo.Reset()
    	While osSetCombineTo.Next

    		osCombineTo.Get( osSetCombineTo.CurrentID )

    		'Create new combination set
    		combinationIDs(0) = osCombineFrom.ID
    		combinationIDs(1) = osCombineTo.ID

    		'Set up combination
    		osCombineFrom.SetCombination(femap.zResultsProcessType.FRPROC_LINEAR, _
    			numCombinationSets, combinationIDs,scaleFactors)

    		'Run combination
    		osCombineFrom.ExpandCombination(True)

    	Wend

    Wend
    
End Sub

I have stepped through and checked that the values inputted in SetCombination are valid, and this line runs fine:

 

 

    		'Set up combination
    		osCombineFrom.SetCombination(femap.zResultsProcessType.FRPROC_LINEAR, _
    			numCombinationSets, combinationIDs,scaleFactors)

The following line should perform the actual linear combination (I think), but instead Femap freezes up and becomes unresponsize:

'Run combination
osCombineFrom.ExpandCombination(True)

There are no changes in memory and I have waited up to 10 minutes with no change. My test model should be very fast.

 

 

This happens when I use Femap 11.3.2 and Femap 11.4.0.

 

Thanks!

Ryan

 

Additional Notes: Solver = NX Nastran, using Femap Desktop License.

When running program, osCombineFrom.program = 36, but documentation for OutputSet says NX Nastran = 38 (5.47.1). femap.zAnalysisProgram.FAP_NX_NASTRAN = 36, so I assume this is just outdated documentation, and not part of the problem.

4 REPLIES

Re: Femap API - Output Set Linear Combination

Creator
Creator

All,

 

I have found a fix to my code, but am still curious as to why:

 

In order to work, I seem to need to use a Femap Output Set objet that hasn't been set to an Output Set in the model. 

 

Fixed:

Option Explicit

Sub Main

    Dim App As femap.model
    Set App = feFemap()

    Dim outSetCombine As femap.OutputSet
    Set outSetCombine = App.feOutputSet

    Dim scaleFactorTo As Double
    Dim scaleFactorFrom As Double

    Dim osCombineTo As femap.OutputSet
    Set osCombineTo = App.feOutputSet

    Dim osCombineFrom As femap.OutputSet
    Set osCombineFrom = App.feOutputSet

    Dim osSetCombineTo As Object

    Dim osSetCombineFrom As Object

    Dim usrChoice As femap.zReturnCode

    Dim numCombinationSets As Long
    numCombinationSets = 2
    Dim combinationIDs(1) As Long
    Dim scaleFactors(1) As Double

    'PROCEDURE

    'Ask user for group to combine against
    usrChoice = App.feSelectOutputSets( "Select output sets to combine from", osSetCombineFrom)
     If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    Else
    	If(osSetCombineFrom Is Nothing) Then
	    	Exit Sub
	    Else
	    	If(osSetCombineFrom.Count = 0)Then
	    		Exit Sub
	    	End If
	    End If
    End If


    'Ask user for scale factor to combine against
    usrChoice = App.feGetReal("Scale Factor (Combine From)", -99999999, 999999999, scaleFactorFrom)
    If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    End If

    'Ask user for groups to combine to
    usrChoice = App.feSelectOutputSets( "Select output sets to combine from", osSetCombineTo)
    If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    Else
    	If(osSetCombineTo Is Nothing) Then
	    	Exit Sub
	    Else
	    	If(osSetCombineTo.Count = 0)Then
	    		Exit Sub
	    	End If
	    End If
    End If

    'Ask user for scale factor to combine to
	usrChoice = App.feGetReal("Scale Factor (Combine To)", -99999999, 999999999, scaleFactorTo)
    If(usrChoice <> femap.zReturnCode.FE_OK) Then
    	Exit Sub
    End If

    'Store scale factors
    scaleFactors(0) = scaleFactorFrom
    scaleFactors(1) = scaleFactorTo

    'For each group to combine against
    While osSetCombineFrom.Next

    	osCombineFrom.Get(osSetCombineFrom.CurrentID )

    	osSetCombineTo.Reset()
    	While osSetCombineTo.Next

    		osCombineTo.Get( osSetCombineTo.CurrentID )

    		'Create new combination set
    		combinationIDs(0) = osCombineFrom.ID
    		combinationIDs(1) = osCombineTo.ID

    		'Set up combination
    		outSetCombine.SetCombination(femap.zResultsProcessType.FRPROC_LINEAR, _
    			numCombinationSets, combinationIDs,scaleFactors)

    		'Run combination
    		outSetCombine.ExpandCombination(True)

    	Wend

    Wend
    
End Sub

 

Does anyone know why?

 

Ryan

Re: Femap API - Output Set Linear Combination

Siemens Phenom Siemens Phenom
Siemens Phenom

Can you upload a model that shows this issue?

Re: Femap API - Output Set Linear Combination

Creator
Creator

Here is Analysis Model of the model (NX Nastran).  <Change test1.BAS to test1.dat>

 

Run  macro with output set from = 1, scale factor from = 1, output set to = 2, scale factor to = 1.

 

The first macro will break it, the second macro will run fine.

 

This crashes Femap for me.

 

Thank you for your help!

Ryan

Re: Femap API - Output Set Linear Combination

Siemens Phenom Siemens Phenom
Siemens Phenom

You are attaching to results, correct?  What is happening here is the first macro is stepping on the pointers that allow FEMAP to parse the *.op2 file when using Attach To Results.  By trying to create a Linear Combination that overwrites Results Set 1, you are interrupting the process of reading the results while trying to use that same data to create new results.  This will not happen when Results are stored within FEMAP as the data is included and saved in memory.  The second macro works because you create a Result Set in an empty ID so there is no interruption.

 

We will include an additional message warnings for users in an upcoming release of FEMAP.