Commit 35ce6505 authored by Chris Cantwell's avatar Chris Cantwell

Merge branch 'feature/gzip' of localhost:nektar

parents ba064069 f1bdff62
......@@ -40,9 +40,13 @@
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/algorithm/string.hpp>
#include <tinyxml/tinyxml.h>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
......@@ -54,6 +58,7 @@ using namespace std;
#include <boost/program_options.hpp>
namespace po = boost::program_options;
namespace io = boost::iostreams;
namespace Nektar
{
......@@ -1060,6 +1065,42 @@ namespace Nektar
}
/**
*
*/
void SessionReader::LoadDoc(
const std::string &pFilename,
TiXmlDocument* pDoc) const
{
if (pFilename.size() > 3 &&
pFilename.substr(pFilename.size() - 3, 3) == ".gz")
{
ifstream file(pFilename.c_str(),
ios_base::in | ios_base::binary);
ASSERTL0(file.good(), "Unable to open file: " + pFilename);
stringstream ss;
io::filtering_streambuf<io::input> in;
in.push(io::gzip_decompressor());
in.push(file);
try
{
io::copy(in, ss);
ss >> (*pDoc);
}
catch (io::gzip_error& e)
{
ASSERTL0(false,
"Error: File '" + pFilename + "' is corrupt.");
}
}
else
{
ifstream file(pFilename.c_str());
ASSERTL0(file.good(), "Unable to open file: " + pFilename);
file >> (*pDoc);
}
}
/**
*
*/
......@@ -1069,13 +1110,9 @@ namespace Nektar
ASSERTL0(pFilenames.size() > 0, "No filenames for merging.");
// Read the first document
TiXmlDocument *vMainDoc = new TiXmlDocument(pFilenames[0]);
ASSERTL0(vMainDoc, "Failed to create XML document object.");
bool loadOkay = vMainDoc->LoadFile();
ASSERTL0(loadOkay, "Unable to load file: " + pFilenames[0] +
". Check XML standards compliance. Error on line: " +
boost::lexical_cast<std::string>(vMainDoc->Row()) +
": " + std::string(vMainDoc->ErrorDesc()));
TiXmlDocument *vMainDoc = new TiXmlDocument;
LoadDoc(pFilenames[0], vMainDoc);
TiXmlHandle vMainHandle(vMainDoc);
TiXmlElement* vMainNektar =
vMainHandle.FirstChildElement("NEKTAR").Element();
......@@ -1085,13 +1122,10 @@ namespace Nektar
// version already present in the loaded XML data.
for (int i = 1; i < pFilenames.size(); ++i)
{
TiXmlDocument vTempDoc (pFilenames[i]);
loadOkay = vTempDoc.LoadFile();
ASSERTL0(loadOkay, "Unable to load file: " + pFilenames[i] +
". Check XML standards compliance. Error on line: " +
boost::lexical_cast<std::string>(vTempDoc.Row()));
TiXmlDocument* vTempDoc = new TiXmlDocument;
LoadDoc(pFilenames[i], vTempDoc);
TiXmlHandle docHandle(&vTempDoc);
TiXmlHandle docHandle(vTempDoc);
TiXmlElement* vTempNektar;
vTempNektar = docHandle.FirstChildElement("NEKTAR").Element();
ASSERTL0(vTempNektar, "Unable to find NEKTAR tag in file.");
......@@ -1109,6 +1143,8 @@ namespace Nektar
vMainNektar->LinkEndChild(q);
p = p->NextSiblingElement();
}
delete vTempDoc;
}
return vMainDoc;
......
......@@ -413,6 +413,10 @@ namespace Nektar
std::vector<std::string> ParseCommandLineArguments(
int argc, char *argv[]);
/// Loads an xml file into a tinyxml doc and decompresses if needed
LIB_UTILITIES_EXPORT void LoadDoc(
const std::string &pFilename,
TiXmlDocument* pDoc) const;
/// Creates an XML document from a list of input files.
LIB_UTILITIES_EXPORT TiXmlDocument *MergeDoc(
const std::vector<std::string> &pFilenames) const;
......
......@@ -530,16 +530,6 @@ namespace Nektar
m_session->LoadParameter("NumQuadPointsError",
m_NumQuadPointsError, 0);
// Read in spatial data
int nq = m_fields[0]->GetNpoints();
m_spatialParameters = MemoryManager<SpatialDomains::SpatialParameters>
::AllocateSharedPtr(m_session, nq);
m_spatialParameters->Read(m_filename);
Array<OneD, NekDouble> x(nq), y(nq), z(nq);
m_fields[0]->GetCoords(x, y, z);
m_spatialParameters->EvaluateParameters(x, y, z);
if (m_session->DefinesFunction("BodyForce"))
{
m_forces = Array<OneD, MultiRegions::ExpListSharedPtr>(v_GetForceDimension());
......
......@@ -41,7 +41,6 @@
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/FieldIO.h>
#include <SpatialDomains/SpatialData.h>
#include <MultiRegions/ExpList.h>
#include <SolverUtils/SolverUtilsDeclspec.h>
......@@ -406,7 +405,6 @@ namespace Nektar
SpatialDomains::BoundaryConditionsSharedPtr m_boundaryConditions;
/// Pointer to graph defining mesh.
SpatialDomains::MeshGraphSharedPtr m_graph;
SpatialDomains::SpatialParametersSharedPtr m_spatialParameters;
/// Filename.
std::string m_filename;
/// Name of the session.
......
......@@ -23,7 +23,6 @@ PyrGeom.cpp
QuadGeom.cpp
SegGeom.cpp
PointGeom.cpp
SpatialData.cpp
TetGeom.cpp
#TriFaceComponent.cpp
TriGeom.cpp
......@@ -55,7 +54,6 @@ PyrGeom.h
QuadGeom.h
SegGeom.h
PointGeom.h
SpatialData.h
SpatialDomainsDeclspec.h
TetGeom.h
#TriFaceComponent.h
......
////////////////////////////////////////////////////////////////////////////////
//
// File: SpatialData.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Storage for spatially-dependent parameters.
//
//
////////////////////////////////////////////////////////////////////////////////
#include <LibUtilities/BasicUtils/VmathArray.hpp>
#include <LibUtilities/BasicUtils/Equation.h>
#include <SpatialDomains/SpatialData.h>
#include <tinyxml/tinyxml.h>
namespace Nektar
{
namespace SpatialDomains
{
/**
* Private default constructor.
*/
/*
SpatialParameters::SpatialParameters():
m_session()
{
}
*/
/**
* Define a set of spatially dependent parameters with \a nq data
* points.
* @param nq Number of data points in the domain.
*/
SpatialParameters::SpatialParameters(const LibUtilities::SessionReaderSharedPtr& pSession, const int nq) :
m_nq(nq),
m_spatialMap(),
m_constMap(),
m_analyticMap(),
m_session(pSession)
{
}
/**
* Define a set of spatially dependent parameters as a deep copy of an
* existing set of parameters.
* @param src Existing set of parameters to copy.
*/
SpatialParameters::SpatialParameters(const SpatialParameters& src) :
m_nq(src.m_nq),
m_spatialMap(),
m_constMap(src.m_constMap),
m_analyticMap(src.m_analyticMap),
m_session(src.m_session)
{
SpatialDataMap::const_iterator x;
for (x = src.m_spatialMap.begin(); x != src.m_spatialMap.end(); ++x)
{
m_spatialMap[x->first] = MemoryManager<SpatialData>
::AllocateSharedPtr(*(x->second));
}
}
/**
* Reads spatially-dependent parameters from an XML file.
* @param infilename XML file.
*/
void SpatialParameters::Read(std::string &infilename)
{
TiXmlDocument doc(infilename);
bool loadOkay = doc.LoadFile();
ASSERTL0(loadOkay, (std::string("Unable to load file: ") +
infilename).c_str());
Read(doc);
}
/**
* Reads spatially-dependent parameters from an XML object.
* @param doc XML document containing spatial data
* definitions.
*/
void SpatialParameters::Read(TiXmlDocument &doc)
{
TiXmlHandle docHandle(&doc);
TiXmlElement* conditions = NULL;
/// Look for all data in CONDITIONS block.
conditions = docHandle.FirstChildElement("NEKTAR")
.FirstChildElement("CONDITIONS").Element();
if (!conditions)
{
return;
}
TiXmlElement *spatialData
= conditions->FirstChildElement("SPATIALDATA");
if (!spatialData)
{
return;
}
// Now read all the different tagged sections
ReadConstantFunctions(spatialData);
ReadAnalyticFunctions(spatialData);
}
/**
* Reads constant-valued spatially-dependent parameters. These are
* defined in the session file with a C tag.
* @param spatialData SpatialData XML element.
*/
void SpatialParameters::ReadConstantFunctions(TiXmlElement *spatialData)
{
TiXmlElement *element = spatialData->FirstChildElement("C");
while (element)
{
std::string variableStr = element->Attribute("NAME");
ASSERTL0(!variableStr.empty(),
"The variable must be specified for the constant "
"spatial data.");
std::string fcnStr = element->Attribute("VALUE");
ASSERTL0(!fcnStr.empty(),
(std::string("Constant for var: ") + variableStr
+ std::string(" must be specified.")).c_str());
m_constMap[variableStr] = atof(fcnStr.c_str());
element = element->NextSiblingElement("C");
}
}
/**
* Reads analytic spatially-dependent function parameters. These are
* defined in the session file with an A tag.
* @param spatialData SpatialData XML element.
*/
void SpatialParameters::ReadAnalyticFunctions(TiXmlElement *spatialData)
{
TiXmlElement *element = spatialData->FirstChildElement("A");
while (element)
{
std::string variableStr = element->Attribute("NAME");
ASSERTL0(!variableStr.empty(),
"The variable must be specified for the analytic "
"spatial data.");
std::string fcnStr = element->Attribute("VALUE");
ASSERTL0(!fcnStr.empty(),
(std::string("Function for var: ") + variableStr
+ std::string(" must be specified.")).c_str());
m_analyticMap[variableStr] = fcnStr;
element = element->NextSiblingElement("A");
}
}
/**
* Evaluates all spatially-dependent parameters at all quadrature,
* points specified by the coordinate arrays. This function must be
* called to populate the list of spatially-dependent data fields.
* @param x x-coordinates of quadrature points.
* @param y y-coordinates of quadrature points.
* @param z z-coordinates of quadrature points.
*/
void SpatialParameters::EvaluateParameters(
const Array<OneD, const NekDouble> x,
const Array<OneD, const NekDouble> y,
const Array<OneD, const NekDouble> z)
{
// First process constant-valued parameters. For this we simply
// fill the spatial data region with the constant.
std::map<std::string, NekDouble>::iterator p;
for (p = m_constMap.begin(); p != m_constMap.end(); p++)
{
SpatialDataSharedPtr fn(MemoryManager<SpatialData>
::AllocateSharedPtr(m_nq));
Vmath::Fill(m_nq, p->second, fn->UpdatePhys(), 1);
m_spatialMap[p->first] = fn;
}
// Now process analytic-valued function parameters. For this we
// evaluate the supplied equation at each quadrature point.
std::map<std::string, std::string>::iterator q;
for (q = m_analyticMap.begin(); q != m_analyticMap.end(); q++)
{
SpatialDataSharedPtr fn(MemoryManager<SpatialData>
::AllocateSharedPtr(m_nq));
LibUtilities::Equation E(m_session, q->second);
E.Evaluate(x, y, z, fn->UpdatePhys());
m_spatialMap[q->first] = fn;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// File: SpatialData.h
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Storage for spatially-dependent parameters.
//
//
////////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_SPATIALDOMAINS_SPATIALDATA_H
#define NEKTAR_SPATIALDOMAINS_SPATIALDATA_H
#include <string>
#include <map>
#include <SpatialDomains/SpatialDomainsDeclspec.h>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
class TiXmlElement;
class TiXmlDocument;
namespace Nektar
{
namespace SpatialDomains
{
/// Defines a domain-wide spatially-varying parameter.
class SpatialData
{
public:
/// Construct new spatially-dependent storage.
SpatialData(int size) :
m_data(size)
{
}
/// Copy existing spatially-dependent storage.
SpatialData(const SpatialData& src) :
m_data(src.m_data)
{
}
/// Returns a const reference to the data.
SPATIAL_DOMAINS_EXPORT inline const Array<OneD, const NekDouble> &GetPhys() const;
/// Returns a non-const reference to the data.
SPATIAL_DOMAINS_EXPORT inline Array<OneD, NekDouble> &UpdatePhys();
private:
/// Default constructor.
SpatialData();
/// Storage for spatially-dependent data.
Array<OneD, NekDouble> m_data;
};
/// Shared pointer to a SpatialData object.
typedef boost::shared_ptr<SpatialData> SpatialDataSharedPtr;
/// Vector of SpatialData pointers.
typedef std::vector< SpatialDataSharedPtr > SpatialDataVector;
/// Iterator for SpatialData vector.
typedef std::vector< SpatialDataSharedPtr >::iterator
SpatialDataVectorIter;
/// Mapping between name and SpatialData.
typedef std::map< std::string, SpatialDataSharedPtr > SpatialDataMap;
/// Constructs a set of spatially-dependent parameters.
class SpatialParameters
{
public:
/// Define a new set of spatially-dependent parameters.
SPATIAL_DOMAINS_EXPORT SpatialParameters(const LibUtilities::SessionReaderSharedPtr& pSession, const int nq);
/// Copies an existing set of spatially-dependent parameters.
SPATIAL_DOMAINS_EXPORT SpatialParameters(const SpatialParameters& src);
/// Reads the set of parameters from an XML file.
SPATIAL_DOMAINS_EXPORT void Read(std::string &infilename);
/// Reads the set of parameters from an XML document object.
SPATIAL_DOMAINS_EXPORT void Read(TiXmlDocument &doc);
/// Evaluate all the parameters at each quadrature point.
SPATIAL_DOMAINS_EXPORT void EvaluateParameters(
const Array<OneD, const NekDouble> x,
const Array<OneD, const NekDouble> y,
const Array<OneD, const NekDouble> z);
/// Determine if a named parameter is defined.
SPATIAL_DOMAINS_EXPORT inline bool Exists(std::string name);
/// Retrieve a single spatially-dependent parameter by name.
SPATIAL_DOMAINS_EXPORT inline SpatialDataSharedPtr& GetData(std::string name);
private:
/// Number of quadrature points in the domain.
int m_nq;
/// List of SpatialData
SpatialDataMap m_spatialMap;
/// List of constant-valued parameter definitions.
std::map<std::string, NekDouble> m_constMap;
/// List of analytic parameter definitions.
std::map<std::string, std::string> m_analyticMap;
/// Shared pointer to the current session
const LibUtilities::SessionReaderSharedPtr& m_session;
/// Default constructor.
// SpatialParameters();
/// Reads constant-valued parameters from XML object.
void ReadConstantFunctions(TiXmlElement *spatialData);
/// Reads analytic parameters from XML object.
void ReadAnalyticFunctions(TiXmlElement *spatialData);
};
/// Shared pointer to a SpatialParameters object.
typedef boost::shared_ptr<SpatialParameters> SpatialParametersSharedPtr;
inline const Array<OneD, const NekDouble> &SpatialData::GetPhys() const
{
return m_data;
}
inline Array<OneD, NekDouble> &SpatialData::UpdatePhys()
{
return m_data;
}
inline bool SpatialParameters::Exists(std::string name)
{
return (m_spatialMap.find(name) != m_spatialMap.end());
}
inline SpatialDataSharedPtr& SpatialParameters::GetData(
std::string name)
{
return m_spatialMap[name];
}
}
}
#endif
......@@ -712,30 +712,14 @@ namespace Nektar
// u3 = u*u*u
Vmath::Vmul(npoints, &physfieldu[0], 1, &u2[0], 1, &u3[0], 1);
if (m_spatialParameters->Exists("a"))
{
Vmath::Vmul(npoints, &m_spatialParameters->GetData("a")->GetPhys()[0], 1, &physfieldu[0], 1, &Ru[0], 1);
Vmath::Vvtvm(npoints, &m_spatialParameters->GetData("a")->GetPhys()[0], 1, &u2[0], 1, &Ru[0], 1, &Ru[0], 1);
Vmath::Svtvm(npoints, -1.0, &u2[0], 1, &Ru[0], 1, &Ru[0], 1);
}
else
{
// Ru = au
Vmath::Smul(npoints, mA, &physfieldu[0], 1, &Ru[0], 1);
// Ru = (-1-a)u*u + au
Vmath::Svtvp(npoints, (-1.0-mA), &u2[0], 1, &Ru[0], 1, &Ru[0], 1);
}
// Ru = au
Vmath::Smul(npoints, mA, &physfieldu[0], 1, &Ru[0], 1);
// Ru = (-1-a)u*u + au
Vmath::Svtvp(npoints, (-1.0-mA), &u2[0], 1, &Ru[0], 1, &Ru[0], 1);
// Ru = u*u*u - (1+a)u*u + au
Vmath::Vadd(npoints, &u3[0], 1, &Ru[0], 1, &Ru[0], 1);
// Ru = k(u*u*u - (1+a)u*u + au)
if (m_spatialParameters->Exists("k"))
{