Commit 0e3baefa authored by Dave Moxey's avatar Dave Moxey Committed by Spencer Sherwin
Browse files

Fix formatting in DriverAdaptive, move GenerateSeqString to ParseUtils and...

Fix formatting in DriverAdaptive, move GenerateSeqString to ParseUtils and replace code elsewhere in the library
parent 38130d73
......@@ -1346,6 +1346,8 @@ namespace Nektar
std::map<int, MeshVertex>::iterator vVertIt;
std::map<std::string, std::string>::iterator vAttrIt;
std::vector<unsigned int> idxList;
// Populate lists of elements, edges and vertices required.
for (boost::tie(vertit, vertit_end) = boost::vertices(pGraph);
vertit != vertit_end;
......@@ -1956,10 +1958,8 @@ namespace Nektar
// which belong to this partition.
for (vIt = m_meshComposites.begin(); vIt != m_meshComposites.end(); ++vIt)
{
bool comma = false; // Set to true after first entity output
bool range = false; // True when entity IDs form a range
int last_idx = -2; // Last entity ID output
std::string vCompositeStr = "";
idxList.clear();
for (unsigned int j = 0; j < vIt->second.list.size(); ++j)
{
// Based on entity type, check if in this partition
......@@ -1991,34 +1991,11 @@ namespace Nektar
break;
}
// Condense consecutive entity IDs into ranges
// last_idx initially -2 to avoid error for ID=0
if (last_idx + 1 == vIt->second.list[j])
{
last_idx++;
range = true;
continue;
}
// This entity is not in range, so close previous range with
// last_idx
if (range)
{
vCompositeStr += "-" + boost::lexical_cast<std::string>(last_idx);
range = false;
}
// Output ID, which is either standalone, or will start a
// range.
vCompositeStr += comma ? "," : "";
vCompositeStr += boost::lexical_cast<std::string>(vIt->second.list[j]);
last_idx = vIt->second.list[j];
comma = true;
}
// If last entity is part of a range, it must be output now
if (range)
{
vCompositeStr += "-" + boost::lexical_cast<std::string>(last_idx);
idxList.push_back(vIt->second.list[j]);
}
std::string vCompositeStr = ParseUtils::GenerateSeqString(idxList);
if (vCompositeStr.length() > 0)
{
vComposites[vIt->first] = vIt->second;
......@@ -2032,18 +2009,16 @@ namespace Nektar
}
}
idxList.clear();
std::string vDomainListStr;
bool comma = false;
for (unsigned int i = 0; i < m_domain.size(); ++i)
{
if (vComposites.find(m_domain[i]) != vComposites.end())
{
vDomainListStr += comma ? "," : "";
comma = true;
vDomainListStr += boost::lexical_cast<std::string>(m_domain[i]);
idxList.push_back(m_domain[i]);
}
}
vDomainListStr = "C[" + vDomainListStr + "]";
vDomainListStr = "C[" + ParseUtils::GenerateSeqString(idxList) + "]";
TiXmlText* vDomainList = new TiXmlText(vDomainListStr);
vDomain->LinkEndChild(vDomainList);
......@@ -2086,19 +2061,20 @@ namespace Nektar
vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
std::vector<unsigned int> vSeq;
ParseUtils::GenerateSeqVector(vSeqStr.c_str(), vSeq);
std::string vListStr;
bool comma = false;
idxList.clear();
for (unsigned int i = 0; i < vSeq.size(); ++i)
{
if (vComposites.find(vSeq[i]) != vComposites.end())
{
vListStr += comma ? "," : "";
comma = true;
vListStr += boost::lexical_cast<std::string>(vSeq[i]);
idxList.push_back(vSeq[i]);
}
}
int p = atoi(vItem->Attribute("ID"));
std::string vListStr = ParseUtils::GenerateSeqString(idxList);
if (vListStr.length() == 0)
{
TiXmlElement* tmp = vItem;
......
......@@ -39,6 +39,7 @@
#include <LibUtilities/BasicConst/NektarUnivTypeDefs.hpp>
#include <vector>
#include <sstream>
#include <boost/version.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
......@@ -155,6 +156,52 @@ namespace Nektar
space_p).full;
}
static std::string GenerateSeqString(const std::vector<unsigned int> &elmtids)
{
std::stringstream idStringStream;
bool setdash = true;
unsigned int endval;
if (elmtids.size() == 0)
{
return std::string("");
}
idStringStream << elmtids[0];
for (int i = 1; i < elmtids.size(); ++i)
{
if (elmtids[i] == elmtids[i - 1] + 1)
{
if (setdash)
{
idStringStream << "-";
setdash = false;
}
if (i == elmtids.size() - 1) // last element
{
idStringStream << elmtids[i];
}
else
{
endval = elmtids[i];
}
}
else
{
if (setdash == false) // finish off previous dash sequence
{
idStringStream << endval;
setdash = true;
}
idStringStream << "," << elmtids[i];
}
}
return idStringStream.str();
}
private:
struct SymbolFunctor
......
This diff is collapsed.
......@@ -41,48 +41,49 @@
namespace Nektar
{
namespace SolverUtils
namespace SolverUtils
{
/// Base class for the adaptive polynomial order driver.
class DriverAdaptive : public Driver
{
public:
friend class MemoryManager<DriverAdaptive>;
/// Creates an instance of this class
static DriverSharedPtr create(
const LibUtilities::SessionReaderSharedPtr &pSession)
{
/// Base class for the development of solvers.
class DriverAdaptive: public Driver
{
public:
friend class MemoryManager<DriverAdaptive>;
DriverSharedPtr p =
MemoryManager<DriverAdaptive>::AllocateSharedPtr(pSession);
p->InitObject();
return p;
}
/// Name of the class
static std::string className;
protected:
/// Constructor
SOLVER_UTILS_EXPORT DriverAdaptive(
const LibUtilities::SessionReaderSharedPtr pSession);
/// Destructor
SOLVER_UTILS_EXPORT virtual ~DriverAdaptive();
/// Creates an instance of this class
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr& pSession) {
DriverSharedPtr p = MemoryManager<DriverAdaptive>::AllocateSharedPtr(pSession);
p->InitObject();
return p;
}
///Name of the class
static std::string className;
protected:
/// Constructor
SOLVER_UTILS_EXPORT DriverAdaptive(const LibUtilities::SessionReaderSharedPtr pSession);
/// Second-stage initialisation
SOLVER_UTILS_EXPORT virtual void v_InitObject(ostream &out = cout);
/// Destructor
SOLVER_UTILS_EXPORT virtual ~DriverAdaptive();
/// Second-stage initialisation
SOLVER_UTILS_EXPORT virtual void v_InitObject(ostream &out = cout);
/// Virtual function for solve implementation.
SOLVER_UTILS_EXPORT virtual void v_Execute(ostream &out = cout);
/// Virtual function for solve implementation.
SOLVER_UTILS_EXPORT virtual void v_Execute(ostream &out = cout);
SOLVER_UTILS_EXPORT void ReplaceExpansion(
Array<OneD, MultiRegions::ExpListSharedPtr>& fields,
map<int, int> deltaP);
SOLVER_UTILS_EXPORT void GenerateSeqString(const std::vector<unsigned int> &elmtids,
std::string &idString);
static std::string driverLookupId;
};
}
} //end of namespace
SOLVER_UTILS_EXPORT void ReplaceExpansion(
Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
map<int, int> deltaP);
#endif //NEKTAR_SOLVERUTILS_DRIVERADAPTIVE_H
static std::string driverLookupId;
};
}
} // end of namespace
#endif // NEKTAR_SOLVERUTILS_DRIVERADAPTIVE_H
......@@ -660,6 +660,8 @@ namespace Nektar
m_session->LoadParameter("NumQuadPointsError",
m_NumQuadPointsError, 0);
m_nchk = 0;
// Zero all physical fields initially
ZeroPhysFields();
}
......
......@@ -359,7 +359,7 @@ namespace Nektar
SOLVER_UTILS_EXPORT inline void CopyToPhysField(const int i,
Array<OneD, NekDouble> &output);
SOLVER_UTILS_EXPORT inline void SetSteps( const int steps);
SOLVER_UTILS_EXPORT inline void SetSteps(const int steps);
SOLVER_UTILS_EXPORT void ZeroPhysFields();
......@@ -406,7 +406,17 @@ namespace Nektar
/// Perform a case-insensitive string comparison.
SOLVER_UTILS_EXPORT int NoCaseStringCompare(
const string & s1, const string& s2) ;
SOLVER_UTILS_EXPORT int GetCheckpointNumber()
{
return m_nchk;
}
SOLVER_UTILS_EXPORT void SetCheckpointNumber(int num)
{
m_nchk = num;
}
SOLVER_UTILS_EXPORT void SetTime(
const NekDouble time)
{
......@@ -462,6 +472,8 @@ namespace Nektar
std::set<std::string> m_loadedFields;
/// Time between checkpoints.
NekDouble m_checktime;
/// Number of checkpoints written so far
int m_nchk;
/// Number of steps to take.
int m_steps;
/// Number of steps between checkpoints.
......@@ -873,9 +885,9 @@ namespace Nektar
return m_timestep;
}
inline void EquationSystem::SetSteps( const int steps)
inline void EquationSystem::SetSteps(const int steps)
{
m_steps= steps;
m_steps = steps;
}
inline void EquationSystem::CopyFromPhysField(const int i,
......
......@@ -45,7 +45,6 @@ namespace Nektar
{
namespace SolverUtils
{
int UnsteadySystem::m_nchk = 1;
/**
* @class UnsteadySystem
*
......
......@@ -69,9 +69,6 @@ namespace Nektar
LibUtilities::TimeIntegrationSolutionSharedPtr m_intSoln;
///
NekDouble m_epsilon;
static int m_nchk;
/// Indicates if explicit or implicit treatment of diffusion is used.
bool m_explicitDiffusion;
/// Indicates if explicit or implicit treatment of advection is used.
......
......@@ -1892,54 +1892,27 @@ namespace Nektar
compMap[LibUtilities::ePrism] = make_pair("R", "R");
compMap[LibUtilities::eHexahedron] = make_pair("H", "H");
std::vector<unsigned int> idxList;
for (cIt = m_meshComposites.begin(); cIt != m_meshComposites.end(); ++cIt)
{
stringstream s;
TiXmlElement *c = new TiXmlElement("C");
bool range = false;
GeometrySharedPtr firstGeom = cIt->second->at(0);
int shapeDim = firstGeom->GetShapeDim();
string tag = (shapeDim < m_meshDimension) ?
compMap[firstGeom->GetShapeType()].second :
compMap[firstGeom->GetShapeType()].first;
int vId = firstGeom->GetGlobalID();
int prevId = vId;
s << " " << tag << "[" << vId;
idxList.clear();
s << " " << tag << "[";
for (int i = 1; i < cIt->second->size(); ++i)
for (int i = 0; i < cIt->second->size(); ++i)
{
// store previous element ID and get current one
prevId = vId;
vId = (*cIt->second)[i]->GetGlobalID();
// continue an already started range
if (prevId > -1 && vId == prevId + 1)
{
range = true;
// if this is the last element, it's the end of a range,
// so write
if (i == cIt->second->size() - 1)
{
s << "-" << vId;
}
continue;
}
// terminate a range, if present
if (range)
{
s << "-" << prevId;
range = false;
}
// write what will be either a single entry or start of new
// range
s << "," << vId;
idxList.push_back((*cIt->second)[i]->GetGlobalID());
}
// terminate
s << "] ";
s << ParseUtils::GenerateSeqString(idxList) << "] ";
c->SetAttribute("ID", cIt->first);
c->LinkEndChild(new TiXmlText(s.str()));
......@@ -1952,21 +1925,14 @@ namespace Nektar
TiXmlElement *domTag = new TiXmlElement("DOMAIN");
stringstream domString;
domString << " C[";
// TODO: Fix this
CompositeMap::iterator cIt2 = m_domain[0].end();
--cIt2;
// @todo Fix this to accomodate multi domain output
idxList.clear();
for (cIt = m_domain[0].begin(); cIt != m_domain[0].end(); ++cIt)
{
domString << cIt->first;
if (cIt != cIt2)
{
domString << ",";
}
idxList.push_back(cIt->first);
}
domString << "] ";
domString << " C[" << ParseUtils::GenerateSeqString(idxList) << "] ";
domTag->LinkEndChild(new TiXmlText(domString.str()));
geomTag->LinkEndChild(domTag);
}
......
......@@ -50,8 +50,8 @@ namespace Utilities
ModuleKey ProcessNumModes::className =
GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eProcessModule, "nummodes"),
ProcessNumModes::create, "Computes number of modes in each direction for each element.");
ModuleKey(eProcessModule, "nummodes"), ProcessNumModes::create,
"Computes number of modes in each direction for each element.");
ProcessNumModes::ProcessNumModes(FieldSharedPtr f) : ProcessModule(f)
{
......@@ -70,97 +70,99 @@ void ProcessNumModes::Process(po::variables_map &vm)
int i, j, s;
int expdim = m_f->m_graph->GetMeshDimension();
int nfields = m_f->m_fielddef[0]->m_fields.size();
int nfields = m_f->m_fielddef[0]->m_fields.size();
int addfields = expdim;
int npoints = m_f->m_exp[0]->GetNpoints();
int npoints = m_f->m_exp[0]->GetNpoints();
Array<OneD, Array<OneD, NekDouble> > outfield(addfields);
int nstrips;
m_f->m_session->LoadParameter("Strip_Z",nstrips,1);
m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
m_f->m_exp.resize(nfields*nstrips);
m_f->m_exp.resize(nfields * nstrips);
for (i = 0; i < addfields; ++i)
{
outfield[i] = Array<OneD, NekDouble>(npoints);
}
vector<MultiRegions::ExpListSharedPtr> Exp(nstrips*addfields);
vector<MultiRegions::ExpListSharedPtr> Exp(nstrips * addfields);
int nExp, nq, offset;
nExp = m_f->m_exp[0]->GetExpSize();
for ( int n = 0; n < nExp; n++)
for (int n = 0; n < nExp; n++)
{
offset = m_f->m_exp[0]->GetPhys_Offset(n);
nq = m_f->m_exp[0]->GetExp(n)->GetTotPoints();
nq = m_f->m_exp[0]->GetExp(n)->GetTotPoints();
for (i = 0; i < expdim; i++)
{
int P = m_f->m_exp[0]->GetExp(n)->GetBasis(i)->GetNumModes();
Array< OneD, NekDouble> result = outfield[i]+offset;
Vmath::Fill( nq, 1.0*P, result,1);
Array<OneD, NekDouble> result = outfield[i] + offset;
Vmath::Fill(nq, 1.0 * P, result, 1);
}
}
for(s = 0; s < nstrips; ++s)
for (s = 0; s < nstrips; ++s)
{
for (i = 0; i < addfields; ++i)
{
int n = s*addfields + i;
Exp[n] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
Exp[n]->UpdatePhys() = outfield[i];
Exp[n]->FwdTrans_IterPerExp(outfield[i],
Exp[n]->UpdateCoeffs());
}
{
int n = s * addfields + i;
Exp[n] =
m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
Exp[n]->UpdatePhys() = outfield[i];
Exp[n]->FwdTrans_IterPerExp(outfield[i], Exp[n]->UpdateCoeffs());
}
}
vector<MultiRegions::ExpListSharedPtr>::iterator it;
for(s = 0; s < nstrips; ++s)
for (s = 0; s < nstrips; ++s)
{
for(i = 0; i < addfields; ++i)
for (i = 0; i < addfields; ++i)
{
it = m_f->m_exp.begin()+s*(nfields+addfields)+nfields+i;
m_f->m_exp.insert(it, Exp[s*addfields+i]);
it = m_f->m_exp.begin() + s * (nfields + addfields) + nfields + i;
m_f->m_exp.insert(it, Exp[s * addfields + i]);
}
}
vector<string > outname;
vector<string> outname;
outname.push_back("P1");
if (addfields >= 2)
{
outname.push_back("P2");
}
if (addfields == 3)
{
outname.push_back("P3");
}
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
= m_f->m_exp[0]->GetFieldDefinitions();
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
m_f->m_exp[0]->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
for(s = 0; s < nstrips; ++s) //homogeneous strip varient
// homogeneous strip variant
for (s = 0; s < nstrips; ++s)
{
for (j = 0; j < nfields + addfields; ++j)
{
for (i = 0; i < FieldDef.size()/nstrips; ++i)
for (i = 0; i < FieldDef.size() / nstrips; ++i)
{
int n = s * FieldDef.size()/nstrips + i;
int n = s * FieldDef.size() / nstrips + i;
if (j >= nfields)
{
FieldDef[n]->m_fields.push_back(outname[j-nfields]);
FieldDef[n]->m_fields.push_back(outname[j - nfields]);
}
else
{
FieldDef[n]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
FieldDef[n]->m_fields.push_back(
m_f->m_fielddef[0]->m_fields[j]);
}
m_f->m_exp[s*(nfields + addfields)+j]->AppendFieldData(FieldDef[n], FieldData[n]);
m_f->m_exp[s * (nfields + addfields) + j]->AppendFieldData(
FieldDef[n], FieldData[n]);
}
}
}
......@@ -168,6 +170,5 @@ void ProcessNumModes::Process(po::variables_map &vm)
m_f->m_fielddef = FieldDef;
m_f->m_data = FieldData;
}
}
}
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