VPTissue Reference Manual
StartupFilePtree.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
21 
22 #include "session/SimSession.h"
25 #include "util/misc/Exception.h"
26 
27 #include <boost/property_tree/exceptions.hpp>
28 #include <boost/optional.hpp>
29 
30 namespace SimPT_Shell {
31 namespace Ws {
32 
33 using namespace std;
34 using namespace boost::property_tree;
35 using boost::optional;
36 using namespace SimPT_Sim::Util;
37 using namespace SimShell::Ws;
38 
40  : StartupFileBase(path)
41 {
42 }
43 
44 shared_ptr<SimShell::Session::ISession>
45 StartupFilePtree::CreateSession(shared_ptr<IProject> proj, shared_ptr<IWorkspace> ws) const
46 {
47  shared_ptr<Session::ISession> session;
48  ptree pt;
49 
50  auto prefs = MergedPreferences::Create(ws, proj);
51  try {
52  pt = ToPtree();
53  } catch (exception& e) {
54  throw Exception("Could not open \"" + m_path + "\": " + e.what());
55  }
56 
57  optional<ptree&> coupled_pt = pt.get_child_optional("vleaf2.coupled_project");
58  if (!coupled_pt) {
59  // It is a regular project.
60  session = make_shared<Session::SimSession>(prefs, pt);
61  } else {
62  // It is a coupled project.
63  session = make_shared<Session::SimSessionCoupled>(prefs, pt, ws);
64  }
65 
66  return session;
67 }
68 
70 {
71  try {
72  ptree pt = ToPtree();
73  if (pt.get<int>("vleaf2.sim_step") == timestep) {
75  s.Initialize(pt);
76  return s.GetState();
77  } else {
78  return SimPT_Sim::SimState();
79  }
80  } catch (exception& e) {
81  throw Exception("GetSimStates(): Could not open \"" + m_path + "\": " + e.what());
82  }
83 }
84 
85 vector<int> StartupFilePtree::GetTimeSteps() const
86 {
87  vector<int> result;
88  try {
89  ptree pt = ToPtree();
90  result.push_back(pt.get<int>("vleaf2.sim_step"));
91  } catch (exception& e) {
92  throw Exception("GetSimSteps() exception: \"" + m_path + "\": " + e.what());
93  }
94  return result;
95 }
96 
97 } // namespace
98 } // namespace
99 
Interface for SimSessionCoupled.
virtual boost::property_tree::ptree ToPtree() const =0
Returns file content in a ptree format.
STL namespace.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Simulator: mesh & parameters, model & algorithms.
Definition: Sim.h:50
Namespace for SimPT shell package.
Definition: Client.cpp:50
Extremely simple Exception root class.
Definition: Exception.h:28
virtual SimPT_Sim::SimState GetSimState(int timestep) const
void Initialize(const boost::property_tree::ptree &pt)
Initialize with full configuration (global info, parameters, random engine, mesh) i...
Namespace for generic workspace classes.
Definition: SimSession.h:32
Interface for MergedPreferences.
Interfaces for simulator session.
Contains the state of the whole Simulator at a given simulation step.
Definition: SimState.h:33
Base class representing the file types used to initiate a session.
StartupFilePtree(const std::string &path)
Constructor.
Header file for Exception class.
virtual std::shared_ptr< SimShell::Session::ISession > CreateSession(std::shared_ptr< SimShell::Ws::IProject > proj, std::shared_ptr< SimShell::Ws::IWorkspace > ws) const
SimState GetState() const
Provide sim state in format suitable for i/o.
Definition: Sim.cpp:122
Interface for StartupFilePtree.
virtual std::vector< int > GetTimeSteps() const