Commit 80f72bac authored by Chris Cantwell's avatar Chris Cantwell

Updated field input/output to add provenance data.

Changed FieldMetadataMap to use string values instead of NekDouble.
parent e0942e63
This diff is collapsed.
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HEAD_HASH)
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
set(HEAD_HASH "${HEAD_REF}")
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
......@@ -118,9 +118,22 @@ MACRO(SET_COMMON_PROPERTIES name)
"${CMAKE_CXX_FLAGS_DEBUG} -fpermissive")
ENDIF()
ENDIF( NOT MSVC)
# Attempt to retrieve git branch and SHA1 hash
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
# Define version
SET_PROPERTY(TARGET ${name}
APPEND PROPERTY COMPILE_DEFINITIONS NEKTAR_VERSION=\"${NEKTAR_VERSION}\")
# Define the git branch and SHA1 hash if we are in a git repository
IF (NOT ${GIT_REFSPEC} STREQUAL "GITDIR-NOTFOUND")
SET_PROPERTY(TARGET ${name}
APPEND PROPERTY COMPILE_DEFINITIONS GIT_SHA1=\"${GIT_SHA1}\" GIT_BRANCH=\"${GIT_REFSPEC}\")
ENDIF ()
SET(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -DNEKTAR_RELEASE")
"${CMAKE_CXX_FLAGS_RELEASE} -DNEKTAR_RELEASE")
ENDIF(NOT ${CMAKE_CXX_FLAGS_DEBUG} MATCHES ".*DNEKTAR_DEBUG.*")
IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
......
......@@ -33,12 +33,23 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <boost/asio/ip/host_name.hpp>
#include <LibUtilities/BasicUtils/FieldIO.h>
#include "zlib.h"
// Buffer size for zlib compression/decompression
#define CHUNK 16384
#ifndef NEKTAR_VERSION
#define NEKTAR_VERSION "Unknown"
#endif
namespace ptime = boost::posix_time;
namespace ip = boost::asio::ip;
namespace Nektar
{
namespace LibUtilities
......@@ -51,8 +62,8 @@ namespace Nektar
std::vector<std::vector<NekDouble> > &fielddata,
FieldMetaDataMap &fieldmetadatamap)
{
ASSERTL1(fielddefs.size() == fielddata.size(),
"Length of fielddefs and fielddata incompatible");
ASSERTL1(fielddefs.size() == fielddata.size(),
"Length of fielddefs and fielddata incompatible");
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration("1.0", "utf-8", "");
......@@ -63,26 +74,55 @@ namespace Nektar
TiXmlElement * root = new TiXmlElement("NEKTAR");
doc.LinkEndChild(root);
FieldMetaDataMap ProvenanceMap;
// Nektar++ release version from VERSION file
ProvenanceMap["NektarVersion"] = string(NEKTAR_VERSION);
// Date/time stamp
ptime::time_facet *facet = new ptime::time_facet("%d-%b-%Y %H:%M:%S");
std::stringstream wss;
wss.imbue(locale(wss.getloc(), facet));
wss << ptime::second_clock::local_time();
ProvenanceMap["Timestamp"] = wss.str();
// Hostname
ProvenanceMap["Hostname"] = ip::host_name();
// Git information
// If built from a distributed package, do not include this
#ifdef GIT_SHA1
ProvenanceMap["GitSHA1"] = string(GIT_SHA1);
#endif
#ifdef GIT_BRANCH
ProvenanceMap["GitBranch"] = string(GIT_BRANCH);
#endif
TiXmlElement * infoTag = new TiXmlElement("Metadata");
root->LinkEndChild(infoTag);
TiXmlElement * v;
FieldMetaDataMap::iterator infoit;
TiXmlElement * provTag = new TiXmlElement("Provenance");
infoTag->LinkEndChild(provTag);
for (infoit = ProvenanceMap.begin(); infoit != ProvenanceMap.end(); ++infoit)
{
v = new TiXmlElement( (infoit->first).c_str() );
v->LinkEndChild(new TiXmlText((infoit->second).c_str()));
provTag->LinkEndChild(v);
}
//---------------------------------------------
// write field info section
// write field info section
if(fieldmetadatamap != NullFieldMetaDataMap)
{
TiXmlElement * infoTag = new TiXmlElement("FIELDMETADATA");
root->LinkEndChild(infoTag);
FieldMetaDataMap::iterator infoit;
for(infoit = fieldmetadatamap.begin(); infoit != fieldmetadatamap.end(); ++infoit)
{
NekDouble val = infoit->second;
stringstream s;
s << val;
TiXmlElement * v = new TiXmlElement( "P" );
v->SetAttribute("PARAM",(infoit->first).c_str());
v->LinkEndChild(new TiXmlText(s.str()));
v = new TiXmlElement( (infoit->first).c_str() );
v->LinkEndChild(new TiXmlText((infoit->second).c_str()));
infoTag->LinkEndChild(v);
}
}
for (int f = 0; f < fielddefs.size(); ++f)
......@@ -346,30 +386,26 @@ namespace Nektar
{
TiXmlHandle docHandle(&doc);
TiXmlElement* master = NULL; // Master tag within which all data is contained.
TiXmlElement* master = 0; // Master tag within which all data is contained.
TiXmlElement* metadata = 0;
master = doc.FirstChildElement("NEKTAR");
ASSERTL0(master, "Unable to find NEKTAR tag in file.");
std::string strLoop = "NEKTAR";
TiXmlElement* metadata = master->FirstChildElement("FIELDMETADATA");
if(!metadata) // section not available so just exit
{
return;
}
else
// Retain original metadata structure for backwards compatibility
// TODO: Remove old metadata format
metadata = master->FirstChildElement("FIELDMETADATA");
if(metadata)
{
TiXmlElement *param = metadata->FirstChildElement("P");
while (param)
{
TiXmlAttribute *paramAttr = param->FirstAttribute();
std::string attrName(paramAttr->Name());
std::string paramString;
if(attrName == "PARAM")
{
paramString.insert(0,paramAttr->Value());
......@@ -381,30 +417,37 @@ namespace Nektar
// Now read body of param
std::string paramBodyStr;
TiXmlNode *paramBody = param->FirstChild();
paramBodyStr += paramBody->ToText()->Value();
fieldmetadatamap[paramString] = paramBodyStr;
param = param->NextSiblingElement("P");
}
}
// New metadata format
metadata = master->FirstChildElement("Metadata");
if(metadata)
{
TiXmlElement *param = metadata->FirstChildElement();
NekDouble value;
std::istringstream paramStrm(paramBodyStr.c_str());
try
{
while(!paramStrm.fail())
{
paramStrm >> value;
}
}
catch(...)
while (param)
{
std::string paramString = param->Value();
if (paramString != "Provenance")
{
ASSERTL0(false,"Failied to read PARAM data");
}
// Now read body of param
TiXmlNode *paramBody = param->FirstChild();
std::string paramBodyStr = paramBody->ToText()->Value();
fieldmetadatamap[paramString] = value;
param = param->NextSiblingElement("P");
fieldmetadatamap[paramString] = paramBodyStr;
}
param = param->NextSiblingElement();
}
}
}
......
......@@ -59,7 +59,7 @@ namespace Nektar
static std::vector<LibUtilities::PointsType> NullPointsTypeVector;
static std::vector<unsigned int> NullUnsignedIntVector;
typedef std::map<std::string, NekDouble> FieldMetaDataMap;
typedef std::map<std::string, std::string> FieldMetaDataMap;
static FieldMetaDataMap NullFieldMetaDataMap;
......
......@@ -1881,7 +1881,7 @@ namespace Nektar
// Update time in field info if required
if(m_fieldMetaDataMap.find("Time") != m_fieldMetaDataMap.end())
{
m_fieldMetaDataMap["Time"] = m_time;
m_fieldMetaDataMap["Time"] = boost::lexical_cast<std::string>(m_time);
}
LibUtilities::Write(outname, FieldDef, FieldData, m_fieldMetaDataMap);
......
......@@ -108,7 +108,8 @@ namespace Nektar
m_session->LoadParameter("CFL", m_cflSafetyFactor, 0.0);
// Set up time to be dumped in field information
m_fieldMetaDataMap["Time"] = m_time;
m_fieldMetaDataMap["Time"] =
boost::lexical_cast<std::string>(m_time);
// Set up filters
LibUtilities::FilterMap::const_iterator x;
......@@ -810,7 +811,7 @@ namespace Nektar
iter = m_fieldMetaDataMap.find("Time");
if(iter != m_fieldMetaDataMap.end())
{
time = iter->second;
time = boost::lexical_cast<NekDouble>(iter->second);
}
}
......
......@@ -360,7 +360,7 @@ namespace Nektar
iter = fieldMetaDataMap.find("Time");
if(iter != fieldMetaDataMap.end())
{
m_lastTime = iter->second;
m_lastTime = boost::lexical_cast<NekDouble>(iter->second);
}
// Extract the data into the modal coefficients
......
......@@ -246,8 +246,8 @@ namespace Nektar
}
// Set up Field Meta Data for output files
m_fieldMetaDataMap["Kinvis"] = m_kinvis;
m_fieldMetaDataMap["TimeStep"] = m_timestep;
m_fieldMetaDataMap["Kinvis"] = boost::lexical_cast<std::string>(m_kinvis);
m_fieldMetaDataMap["TimeStep"] = boost::lexical_cast<std::string>(m_timestep);
}
IncNavierStokes::~IncNavierStokes(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment