Welcome to the RAS Solution Forums HECRAS Controller Closing HEC-RAS after every run

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #8189
    Anonymous
    Guest

    I’m trying to do a sensitivity analysis for HEC-RAS and have developed a code to run the model multiple times from MATLAB by varying geometry parameters. When i do this by calling the controller for HEC-RAS 4.1, the computation window opens and closes after every run. However, when i do the same using HEC-RAS 5.01, the computational window does not close by itself after every run, leading to an out of memory error. what is the right command to close hecras after every run from MATLAB?

    #13520
    Chris G.
    Keymaster

    In version 5 and later, you need to include the QuitRAS subroutine at the end of your procedure. See example below…

    Sub QuitRAS()

    ‘**********************************************************
    ‘Demonstrates the QuitRAS subroutine.

    ‘Written by Christopher Goodell
    ‘May 7, 2013

    ‘Closes HEC-RAS. _
    Every procedure that instantiates an HECRASController _
    class must conclude with a call to the QuitRAS _
    subroutine.

    ‘Tested with the BEAVCREK.prj data set. Can be _
    used with any HEC-RAS data set.
    ‘**********************************************************

    ‘Open a new HEC-RAS Project
    Dim RC As New RAS503.HECRASController
    mSamples.OpenRASProjectByRef RC

    ‘Show HEC-RAS
    RC.ShowRAS

    ‘Message the user to click to close HEC-RAS
    MsgBox “Click OK to close HEC-RAS.”

    ‘Close HEC-RAS
    RC.QuitRAS ‘This is what you have to add to close HEC-RAS in Version 5 or later.

    End Sub

    Sub OpenRASProjectByRef(ByRef RC As RAS503.HECRASController)

    ‘**********************************************************
    ‘Demonstrates Project_Open subroutine and how to pass the _
    HECRASController as a reference.

    ‘Written by Christopher Goodell
    ‘July 3, 2012

    ‘Opens a RAS project by being called from another _
    subroutine
    ‘**********************************************************

    ‘Open the HEC-RAS Project
    Dim strFilename As String
    Sheets(“RASProjects”).Select
    strFilename = Range(“C4”).Value
    RC.Project_Open strFilename

    End Sub

    #13521
    Anonymous
    Guest

    Thank you for this information Chris.

    #13522
    Anonymous
    Guest

    In continuation with the previous doubt, when i run the unsteady model within a loop, the lines after the “h.Compute_CurrentPlan(0,0)” in the matlab script start executing before the HEC-RAS model is run. I tried different commands like “waitfor” to delay to pause the execution of the subsequent lines but with no success.

    Could you tell me what mistake I’m making here? Thanks in advance.

    Regards,
    Bharath

    #13523
    Chris G.
    Keymaster

    Bharath-

    There are three arguments to include with the Compute_CurrentPlan Function.

    1. nmsg (long). the number of returned messages
    2. msg() (string). messages returned from the HECRASController during computations.
    3. BlockingMode (boolean). True or False. If blocking mode is set to false, then code will continue to be readh while HEC-RAS is computing. So you want this to be set to True. You omitted the BlockingMode argument from your Compute_CurrentPlan call, so by default it is set to false. Your call should look more like this (in VBA syntax):

    ‘Compute the current plan.
    Dim lngMessages As Long
    Dim strMessages() As String
    Dim blnDidItCompute As Boolean
    blnDidItCompute = RC.Compute_CurrentPlan(lngMessages, strMessages(), True)

    With the 3rd argument set to “True”, the code will pause while HEC-RAS is computing.

    #13524
    SALAKA
    Participant

    Hi Chris,

    first thanks for your work here.

    Currently I’m trying to solve a problem when controlling HEC-RAS from Matlab. I’m writing
    to this thread as it seems to be a very similar problem.

    Basically I can’t get the blocking mode working, so HEC-RAS gets closed before finishing
    the computation.

    Currently the Code launches the computation with this line:

    h.Compute_CurrentPlan(0,0);

    To enable the blocking mode I tried several combination of arguments, but always get the error:
    No method ‘Compute_CurrentPlan’ with matching signature found for class ‘COM.RAS503_HECRASCONTROLLER’.

    What are the right arguments for Compute_CurrentPlan to enable the blocking mode?

    Thanks for your help, regards
    Saskia

    #13525
    Chris G.
    Keymaster

    As mentioned above, the arguments are:

    ‘Compute the current plan.
    Dim lngMessages As Long
    Dim strMessages() As String
    Dim blnDidItCompute As Boolean

    blnDidItCompute = RC.Compute_CurrentPlan(lngMessages, strMessages(), True)

    With the 3rd argument set to “True”, the code will pause while HEC-RAS is computing.

    Let me know if this works. I’ll check around to see if there is a MatLab compatibility issue with this command.

    #13526
    SALAKA
    Participant

    Hi Chris,

    I now tried it using Excel with VBA, and there your code works perfectly.

    When using matlab I can’t get this to work. As explained before I always
    get an error that the method ‘Compute_CurrentPlan’ doesn’t work with the
    passed arguments.

    But for now that’s no problem for me, as it’s working with VBA. Thank you!
    Saskia

    #13527
    Chris G.
    Keymaster

    This from Arturo Leon: “The error says: No method ‘Compute_CurrentPlan’ with matching signature found for class ‘COM.RAS503_HECRASCONTROLLER’. It appears that the Matlab class was not defined. In our paper I defined the class as “h”, so to perform any operation the “h. XXXXXX” needs to be used, including defining each instance of HEC-RAS. For using HEC-RAS in parallel computing or to do multiple computations in series, h is replaced by a vector h(i) where “i” is the ID of the simulation (e.g., 1 to 100). For instance, to open a single instance of HEC-RAS 5.0, h=actxserver(‘RAS500.HECRASCONTROLLER’) is used in the paper. I would suggest the student to check our paper available at: http://www2.egr.uh.edu/~aleon3/papers_PDF/Journal/HEC_RAS_Controller.pdf”

    #13528
    Bharath
    Participant

    Hi Chris,

    Thanks for providing me with this information. I tried this technique, but it looks like I’m stuck with a problem that seems trivial, but I’m missing it.

    Could you explain to me what ‘h.Compute_CurrentPlan(0,0)’ means exactly? both zeros are integers whereas the syntax for this shows
    ‘Compute_CurrentPlan(handle, int32, SafeArray Pointer(string))’.

    Trying to introduce a third Boolean term within the bracket results in the following error.

    Error using
    COM.RAS501_HECRASCONTROLLER/Compute_CurrentPlan
    Invoke Error, Dispatch Exception: Exception
    occurred.

    or

    No method ‘Compute_CurrentPlan’ with
    matching signature found for class
    ‘COM.RAS501_HECRASCONTROLLER’.

    I guess it is due to my incomplete understanding of the term “SafeArray Pointer” and how this particular command works.

    Any help would be much appreciated as I’m heading towards a deadline and I’m stuck here.

    Warm regards,
    Bharath

    #13529
    Chris G.
    Keymaster

    I don’t know MatLab well enough to say what the problem is.

    #13530
    Bharath
    Participant

    Thank you Chris. I’ll try and build on your suggestion and see if I can find a solution.

    #13531
    Marceroli
    Participant

    I’m using QuitRas for closing HECRAS into a “for”. It works perfectly but every iteration it ask me if I want to save the project before leave HEC-Ras and I don’t want to click YES hundred of times. Is there any way to skip that message when I use the QuitRas subroutine?

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.