Execute a series of Actions from a file without destroying the engine

Is there a way to execute a series of Actions from a file without destroying the engine?

Currently the following method:

bool BioGearsEngine::ExecuteScenario(const char *scenarioFile, const char *resultsFile = nullptr, SEScenarioCustomExec *cExec = nullptr)

will parse and execute the Actions in the scenario file, then it will re-converge to a steady state. After execution, the engine will be destroyed and no subsequent ExecuteScenario methods can be called. The desired behavior would be for the engine to accept subsequent calls without re-convergence. Can this be done currently with different methods?

Comments

  • abrayabray Entry Level
    The v3.0 API does not support this.
    I think that should pretty straight forward for me to support in the upcoming beta build.
    I will keep you posted on this.
    dansvcom3d
  • abrayabray Entry Level
    Turns out that supporting this feature through the Physiology Engine Interface is a little more tricky than I had anticipated. I will have to work through a couple of road blocks. So this feature will not make it into 4.0
    BUT, here is some code you can use that will get you what you want, it just will not be encapsulated in the ExecuteScenario method just yet, but should be what you need


    void HowToScenarioBase()
    {
    std::cout << "HowToScenarioBase" << std::endl;
    // Create our engine
    std::unique_ptr<PhysiologyEngine> bg = CreateBioGearsEngine("HowToScenarioBase.log");

    //Let's read the scenario we want to base this dynamic engine on
    SEScenario sce(bg->GetSubstanceManager());
    sce.LoadScenarioFile("YourScenario.xml");

    // Copy over any conditions to a const array
    std::vector<const SECondition*> conditions;
    for (SECondition* c : sce.GetConditions())
    conditions.push_back(c);

    // Start up a dynamic engine
    if (!bg->InitializeEngine(sce.GetPatientFile().c_str(), &conditions))
    {
    std::cerr << "Could not initialize engine, check the error\n";
    return;
    }

    // Let's request data do be tracked that is in the scenario
    HowToTracker tracker(*bg);
    for (SEDataRequest* dr : sce.GetRequestedData())
    tracker.m_Requests.push_back(dr);
    // NOTE IF YOU DO THIS, MODIFY THE HowToTracker NOT TO DELETE THE DATA REQUEST
    // AS THE SCENARIO IS CURRENTLY MANAGING THAT MEMORY!!
    // You are free to add any new data you would like to request

    SEAdvanceTime* adv;
    // Now run the scenario actions
    for (SEAction* a : sce.GetActions())
    {
    // We want the tracker to process an advance time action so it will write each time step of data to our track file
    adv = dynamic_cast<SEAdvanceTime*>(a);
    if (adv != nullptr)
    tracker.AdvanceModelTime(adv->GetTime(SEScalarTime::s));
    else
    bg->ProcessAction(*a);
    }

    // At this point your engine is where you want it to be
    // You could read in a new scenario and run it's actions
    // or programmatically add actions as your applications sees fit
    }


    This code will also be provided in the HowTo-SceanrioBase.cpp in the 4.0 SDK
Sign In or Register to comment.