From fd659c09ea84725c738ee74eab6aaa707bdef76f Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 2 May 2015 19:41:18 -0400 Subject: [PATCH] [1D] Fix saving multiple flame profiles to a single XML file Broken by the change in b0e5b13913. Modify the save_restore test to cover this case. --- interfaces/cython/cantera/test/test_onedim.py | 3 +++ src/oneD/OneDim.cpp | 10 +++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index fbce5b7ab..110ed013e 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -252,6 +252,9 @@ class TestFreeFlame(utilities.CanteraTest): self.sim.save(filename, 'test', loglevel=0) + # Save a second solution to the same file + self.sim.save(filename, 'test2', loglevel=0) + # Create flame object with dummy initial grid self.sim = ct.FreeFlame(self.gas) self.sim.restore(filename, 'test', loglevel=0) diff --git a/src/oneD/OneDim.cpp b/src/oneD/OneDim.cpp index ea0c410b3..d204611fc 100644 --- a/src/oneD/OneDim.cpp +++ b/src/oneD/OneDim.cpp @@ -380,9 +380,8 @@ void OneDim::save(const std::string& fname, std::string id, ::time(&aclock); // Get time in seconds struct tm* newtime = localtime(&aclock); // Convert time to struct tm form - XML_Node root("doc"); + XML_Node root("ctml"); ifstream fin(fname.c_str()); - XML_Node* ct; if (fin) { root.build(fin); // Remove existing solution with the same id @@ -391,11 +390,8 @@ void OneDim::save(const std::string& fname, std::string id, same_ID->parent()->removeChild(same_ID); } fin.close(); - ct = &root.child("ctml"); - } else { - ct = &root.addChild("ctml"); } - XML_Node& sim = ct->addChild("simulation"); + XML_Node& sim = root.addChild("simulation"); sim.addAttribute("id",id); addString(sim,"timestamp",asctime(newtime)); if (desc != "") { @@ -411,7 +407,7 @@ void OneDim::save(const std::string& fname, std::string id, if (!s) { throw CanteraError("save","could not open file "+fname); } - ct->write(s); + root.write(s); s.close(); writelog("Solution saved to file "+fname+" as solution "+id+".\n", loglevel); }