Commit 17362acb authored by Guido Novati's avatar Guido Novati

minor changes needed to make 2d code write easily readable files, changes to meshmap are not needed

parent 47e793dc
......@@ -111,10 +111,11 @@ public:
const double h = (maxextent / std::max(NX, std::max(NY, NZ)));
const double extents[3] = {h*NX, h*NY, h*NZ};
constexpr int bSizes[3] = {Block::sizeX, Block::sizeY, Block::sizeZ};
const unsigned int nBlocks[3] = {NX, NY, NZ};
for (int i = 0; i < 3; ++i)
{
MeshMap<Block>* m = new MeshMap<Block>(0.0, extents[i], nBlocks[i]);
MeshMap<Block>* m = new MeshMap<Block>(0.0, extents[i], nBlocks[i], bSizes[i]);
UniformDensity uniform;
m->init(&uniform); // uniform only for this constructor
m_mesh_maps.push_back(m);
......
......@@ -74,12 +74,16 @@ void DumpHDF5(const TGrid &grid,
///////////////////////////////////////////////////////////////////////////
// write mesh
const bool bUniformAllDir = grid.getMeshMap(0).uniform() &&
grid.getMeshMap(1).uniform() &&
grid.getMeshMap(2).uniform();
std::vector<int> mesh_dims;
std::vector<std::string> dset_name;
dset_name.push_back("/vx");
dset_name.push_back("/vy");
dset_name.push_back("/vz");
for (size_t i = 0; i < 3; ++i)
for (size_t i = 0; i < 3 && not bUniformAllDir; ++i)
{
const MeshMap<B>& m = grid.getMeshMap(i);
std::vector<double> vertices(m.ncells()+1, m.start());
......@@ -179,19 +183,44 @@ void DumpHDF5(const TGrid &grid,
fprintf(xmf, " <Domain>\n");
fprintf(xmf, " <Grid GridType=\"Uniform\">\n");
fprintf(xmf, " <Time Value=\"%e\"/>\n\n", absTime);
fprintf(xmf, " <Topology TopologyType=\"3DRectMesh\" Dimensions=\"%d %d %d\"/>\n\n", mesh_dims[2], mesh_dims[1], mesh_dims[0]);
fprintf(xmf, " <Geometry GeometryType=\"VxVyVz\">\n");
fprintf(xmf, " <DataItem Name=\"mesh_vx\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[0]);
fprintf(xmf, " %s:/vx\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"mesh_vy\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[1]);
fprintf(xmf, " %s:/vy\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"mesh_vz\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[2]);
fprintf(xmf, " %s:/vz\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Geometry>\n\n");
fprintf(xmf, " <Attribute Name=\"data\" AttributeType=\"%s\" Center=\"Cell\">\n", TStreamer::getAttributeName());
if(bUniformAllDir)
{
fprintf(xmf, " <Topology TopologyType=\"3DCORECTMesh\" Dimensions=\"%d %d %d\"/>\n", (int)dims[0], (int)dims[1], (int)dims[2]);
fprintf(xmf, " <Geometry GeometryType=\"ORIGIN_DXDYDZ\">\n");
fprintf(xmf, " <DataItem Name=\"Origin\" Dimensions=\"3\" NumberType=\"Float\" Precision=\"4\" Format=\"XML\">\n");
fprintf(xmf, " %e %e %e\n", 0.,0.,0.);
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"Spacing\" Dimensions=\"3\" NumberType=\"Float\" Precision=\"4\" Format=\"XML\">\n");
fprintf(xmf, " %e %e %e\n", grid.getH(),grid.getH(),grid.getH());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Geometry>\n\n");
fprintf(xmf, " <Attribute Name=\"data\" AttributeType=\"%s\" Center=\"Node\">\n", TStreamer::getAttributeName());
}
else
{
fprintf(xmf, " <Topology TopologyType=\"3DRectMesh\" Dimensions=\"%d %d %d\"/>\n\n", mesh_dims[2], mesh_dims[1], mesh_dims[0]);
fprintf(xmf, " <Geometry GeometryType=\"VxVyVz\">\n");
fprintf(xmf, " <DataItem Name=\"mesh_vx\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[0]);
fprintf(xmf, " %s:/vx\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"mesh_vy\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[1]);
fprintf(xmf, " %s:/vy\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"mesh_vz\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[2]);
fprintf(xmf, " %s:/vz\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Geometry>\n\n");
fprintf(xmf, " <Attribute Name=\"data\" AttributeType=\"%s\" Center=\"Cell\">\n", TStreamer::getAttributeName());
}
fprintf(xmf, " <DataItem Dimensions=\"%d %d %d %d\" NumberType=\"Float\" Precision=\"%d\" Format=\"HDF\">\n", (int)dims[0], (int)dims[1], (int)dims[2], (int)dims[3], (int)sizeof(hdf5Real));
fprintf(xmf, " %s:/data\n",(filename.str()+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
......
......@@ -60,9 +60,11 @@ template <typename TBlock>
class MeshMap
{
public:
MeshMap(const double xS, const double xE, const unsigned int Nblocks) :
// constructor used to assume uniform cells in all directions!FIX EVERYWHERE
MeshMap(const double xS, const double xE, const unsigned int Nblocks,
const int nElemPerBlock = TBlock::sizeX) :
m_xS(xS), m_xE(xE), m_extent(xE-xS), m_Nblocks(Nblocks),
m_Ncells(Nblocks*TBlock::sizeX), // assumes uniform cells in all directions!
m_Ncells(Nblocks*nElemPerBlock), m_blockSize(nElemPerBlock),
m_uniform(true), m_initialized(false)
{}
......@@ -85,8 +87,8 @@ public:
for (std::size_t i = 0; i < m_Nblocks; ++i)
{
double delta_block = 0.0;
for (std::size_t j = 0; j < TBlock::sizeX; ++j)
delta_block += m_grid_spacing[i*TBlock::sizeX + j];
for (std::size_t j = 0; j < m_blockSize; ++j)
delta_block += m_grid_spacing[i * m_blockSize + j];
m_block_spacing[i] = delta_block;
}
......@@ -127,13 +129,13 @@ public:
inline double* get_grid_spacing(const unsigned int bix)
{
assert(m_initialized && bix >= 0 && bix < m_Nblocks);
return &m_grid_spacing[bix*TBlock::sizeX];
return &m_grid_spacing[bix * m_blockSize];
}
inline const double* get_grid_spacing(const unsigned int bix) const
{
assert(m_initialized && bix >= 0 && bix < m_Nblocks);
return &m_grid_spacing[bix*TBlock::sizeX];
return &m_grid_spacing[bix * m_blockSize];
}
inline double* data_grid_spacing() { return m_grid_spacing; }
......@@ -145,6 +147,7 @@ private:
const double m_extent;
const unsigned int m_Nblocks;
const unsigned int m_Ncells;
const unsigned int m_blockSize;
bool m_uniform;
bool m_initialized;
......
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