Commit 39badfaa authored by fabianw's avatar fabianw

Merge branch 'MeshGridFix'

parents 47e793dc 810d2c30
*~
*.o
*.swp
*.swo
*.bak
......
......@@ -61,6 +61,8 @@ private:
char** vArgV;
bool bStrictMode, bVerbose;
bool _isnumber(const std::string& s) const;
protected:
std::map<std::string,Value> mapArguments;
......
......@@ -39,7 +39,6 @@ protected:
const double maxextent;
const unsigned int N, NX, NY, NZ;
const bool m_own_mesh_maps;
std::vector<MeshMap<Block>*> m_mesh_maps;
void _dealloc()
......@@ -48,13 +47,10 @@ protected:
alloc.deallocate(m_blocks, N);
if (m_own_mesh_maps)
for (size_t i = 0; i < m_mesh_maps.size(); ++i)
{
for (size_t i = 0; i < m_mesh_maps.size(); ++i)
{
delete m_mesh_maps[i];
m_mesh_maps[i] = NULL;
}
delete m_mesh_maps[i];
m_mesh_maps[i] = NULL;
}
}
......@@ -103,18 +99,18 @@ public:
typedef typename Block::RealType Real; // Block MUST provide `RealType`.
Grid(const unsigned int _NX, const unsigned int _NY = 1, const unsigned int _NZ = 1, const double _maxextent = 1) :
m_blocks(NULL), maxextent(_maxextent), N(_NX*_NY*_NZ), NX(_NX), NY(_NY), NZ(_NZ),
m_own_mesh_maps(true)
m_blocks(NULL), maxextent(_maxextent), N(_NX*_NY*_NZ), NX(_NX), NY(_NY), NZ(_NZ)
{
_alloc();
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);
......@@ -132,19 +128,20 @@ public:
}
}
Grid(MeshMap<Block>* const mapX, MeshMap<Block>* const mapY, MeshMap<Block>* const mapZ,
const int _NX, const int _NY=1, const int _NZ=1) :
Grid(const MeshMap<Block>* const mapX,
const MeshMap<Block>* const mapY,
const MeshMap<Block>* const mapZ,
const int _NX, const int _NY=1, const int _NZ=1) :
m_blocks(NULL),
maxextent(-1.0), // not used
N(_NX*_NY*_NZ),
NX(_NX), NY(_NY), NZ(_NZ),
m_own_mesh_maps(false)
NX(_NX), NY(_NY), NZ(_NZ)
{
_alloc();
m_mesh_maps.push_back(mapX);
m_mesh_maps.push_back(mapY);
m_mesh_maps.push_back(mapZ);
m_mesh_maps.push_back(new MeshMap<Block>(*mapX));
m_mesh_maps.push_back(new MeshMap<Block>(*mapY));
m_mesh_maps.push_back(new MeshMap<Block>(*mapZ));
for(unsigned int iz=0; iz<NZ; iz++)
for(unsigned int iy=0; iy<NY; iy++)
......@@ -153,7 +150,11 @@ public:
const long long blockID = _encode(ix, iy, iz);
const int idx[3] = {(int)ix, (int)iy, (int)iz};
m_vInfo.push_back(BlockInfo(blockID, idx, mapX, mapY, mapZ, _linaccess(blockID)));
m_vInfo.push_back(BlockInfo(blockID, idx,
m_mesh_maps[0], // mmapX
m_mesh_maps[1], // mmapY
m_mesh_maps[2], // mmapZ
_linaccess(blockID)));
}
}
......
......@@ -160,14 +160,16 @@ public:
}
GridMPI(MeshMap<Block>* const mapX, MeshMap<Block>* const mapY, MeshMap<Block>* const mapZ,
GridMPI(const MeshMap<Block>* const mapX,
const MeshMap<Block>* const mapY,
const MeshMap<Block>* const mapZ,
const int npeX, const int npeY, const int npeZ,
const int nX=0, const int nY=0, const int nZ=0,
const MPI_Comm comm = MPI_COMM_WORLD): TGrid(mapX,mapY,mapZ,nX,nY,nZ), timestamp(0), worldcomm(comm)
{
assert(mapX->nblocks() == static_cast<size_t>(npeX*nX));
assert(mapY->nblocks() == static_cast<size_t>(npeY*nY));
assert(mapZ->nblocks() == static_cast<size_t>(npeZ*nZ));
assert(this->m_mesh_maps[0]->nblocks() == static_cast<size_t>(npeX*nX));
assert(this->m_mesh_maps[1]->nblocks() == static_cast<size_t>(npeY*nY));
assert(this->m_mesh_maps[2]->nblocks() == static_cast<size_t>(npeZ*nZ));
blocksize[0] = Block::sizeX;
blocksize[1] = Block::sizeY;
......@@ -196,7 +198,6 @@ public:
const std::vector<BlockInfo> vInfo = TGrid::getBlocksInfo();
MeshMap<Block>* const ptr_map[3] = {mapX, mapY, mapZ};
for(size_t i=0; i<vInfo.size(); ++i)
{
BlockInfo info = vInfo[i];
......@@ -205,11 +206,11 @@ public:
{
info.index[j] += mypeindex[j]*mybpd[j];
info.origin[j] = ptr_map[j]->block_origin(info.index[j]);
info.origin[j] = this->m_mesh_maps[j]->block_origin(info.index[j]);
info.block_extent[j] = ptr_map[j]->block_width(info.index[j]);
info.block_extent[j] = this->m_mesh_maps[j]->block_width(info.index[j]);
info.ptr_grid_spacing[j] = ptr_map[j]->get_grid_spacing(info.index[j]);
info.ptr_grid_spacing[j] = this->m_mesh_maps[j]->get_grid_spacing(info.index[j]);
}
cached_blockinfo.push_back(info);
......
......@@ -12,6 +12,7 @@
#include <cassert>
#include <cstddef>
#include <string>
#include <cstring>
#include "Cubism/Common.h"
......@@ -60,12 +61,27 @@ template <typename TBlock>
class MeshMap
{
public:
MeshMap(const double xS, const double xE, const unsigned int Nblocks) :
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)
{}
MeshMap(const MeshMap& c):
m_xS(c.m_xS), m_xE(c.m_xE), m_extent(c.m_extent), m_Nblocks(c.m_Nblocks),
m_Ncells(c.m_Ncells), m_blockSize(c.m_blockSize),
m_uniform(c.m_uniform), m_initialized(c.m_initialized),
m_kernel_name(c.m_kernel_name)
{
if (m_initialized)
{
_alloc();
std::memcpy(m_grid_spacing, c.m_grid_spacing, m_Ncells*sizeof(double));
std::memcpy(m_block_spacing, c.m_block_spacing, m_Nblocks*sizeof(double));
}
}
~MeshMap()
{
if (m_initialized)
......@@ -75,6 +91,8 @@ public:
}
}
MeshMap& operator=(const MeshMap& rhs) = delete;
void init(const MeshDensity* const kernel, const unsigned int ghostS=0, const unsigned int ghostE=0, double* const ghost_spacing=NULL)
{
_alloc();
......@@ -85,8 +103,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 +145,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 +163,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;
......
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <regex> // C++11
#include <sstream>
#include <limits>
#include "Cubism/ArgumentParser.h"
......@@ -98,6 +101,13 @@ bool CommandlineParser::check(std::string key) const
return _existKey(key,mapArguments);
}
bool CommandlineParser::_isnumber(const std::string& s) const
{
char* end = NULL;
strtod(s.c_str(), &end);
return end != s.c_str(); // only care if the number is numeric or not. This includes nan and inf
}
CommandlineParser::CommandlineParser(const int argc, char **argv)
: iArgC(argc), vArgV(argv), bStrictMode(false), bVerbose(true)
{
......@@ -115,9 +125,12 @@ CommandlineParser::CommandlineParser(const int argc, char **argv)
for (int j=i+1; j<argc; j++)
{
// if the current value is numeric and (possibly) negative,
// do not interpret it as a key
const bool leadingDash = (argv[j][0] == '-');
const bool isNumeric = std::regex_match(argv[j], std::regex("(\\+|-)?[0-9]*(\\.[0-9]*)?((e|E)(\\+|-)?[0-9]*)?"));
// do not interpret it as a key.
// XXX: [fabianw@mavt.ethz.ch; 2019-03-28] WARNING:
// This will treat -nan as a NUMBER and not as a KEY
std::string sval(argv[j]);
const bool leadingDash = (sval[0] == '-');
const bool isNumeric = _isnumber(sval);
if (leadingDash && !isNumeric)
break;
else
......
SHELL := /bin/bash
CC = g++
extra ?=
CFLAGS = -g -O2 -I../../include
CFLAGS+= $(extra)
CFLAGS+= -Wall -Wextra -Wfloat-equal -Wundef -Wcast-align
CFLAGS+= -Wwrite-strings -Wmissing-declarations -Wredundant-decls
CFLAGS+= -Wshadow -Woverloaded-virtual -Wuninitialized
CFLAGS+= -Wpedantic -Wno-unused-parameter # does not make much sense with function overloading
.PHONY: all clean
all: testArgumentParser.cpp
$(CC) $(CFLAGS) -o testArgumentParser testArgumentParser.cpp ../../src/ArgumentParser.cpp
clean:
rm -f testArgumentParser *.o
#!/usr/bin/env bash
# File : run.sh
# Created : Thu Mar 28 2019 06:11:33 PM (+0100)
# Author : Fabian Wermelinger
# Description: Run testArgumentParser
# Copyright 2019 ETH Zurich. All Rights Reserved.
set -e
./testArgumentParser -conf test.conf \
-arg1 1.0e-001 \
-arg2 -1.0e-001 \
-arg3 1.0e1 \
-arg4 -1.0e+001 \
-arg5 -1.0e400 \
-arg6 +1.0e400 \
-arg7 1.0e400 \
-arg8 nan \
-arg9 -nan \
-arg10
# File : test.conf
# Created : Thu Mar 28 2019 05:48:19 PM (+0100)
# Author : Fabian Wermelinger
# Description: Test configuration file
# ./testArgumentParser -conf test.conf
# Copyright 2019 ETH Zurich. All Rights Reserved.
# strings
s1 string
+s1 concatenate more strings here
-s2 leading dashes are ok here
# floats
f1 1.0e-001
f2 -1.0e-001
f3 1.0e1
f4 -1.0e+001
f5 -1.0e400
f6 +1.0e400
f7 1.0e400
f8 nan
f9 -nan
// File : testArgumentParser.cpp
// Created : Thu Mar 28 2019 05:27:31 PM (+0100)
// Author : Fabian Wermelinger
// Description: Test Cubism ArgumentParser
// Copyright 2019 ETH Zurich. All Rights Reserved.
#include <iostream>
#include "Cubism/ArgumentParser.h"
using namespace cubism;
using namespace std;
int main(int argc, char* argv[])
{
ArgumentParser parser(argc, argv);
if (parser.exist("-conf"))
parser.readFile(parser("-conf").asString());
parser.print_args();
cout << "s1 = " << parser("s1").asString() << endl;
cout << "s2 = " << parser("s2").asString() << endl;
cout << "f1 = " << parser("f1").asDouble() << endl;
cout << "f2 = " << parser("f2").asDouble() << endl;
cout << "f3 = " << parser("f3").asDouble() << endl;
cout << "f4 = " << parser("f4").asDouble() << endl;
cout << "f5 = " << parser("f5").asDouble() << endl;
cout << "f6 = " << parser("f6").asDouble() << endl;
cout << "f7 = " << parser("f7").asDouble() << endl;
cout << "f8 = " << parser("f8").asDouble() << endl;
cout << "f9 = " << parser("f9").asDouble() << endl;
return 0;
}
......@@ -30,7 +30,7 @@ struct Block
{
typedef TReal ElementType;
typedef TReal element_type;
typedef TReal Real;
typedef TReal RealType;
static constexpr size_t sizeX = BLOCK_SIZE;
static constexpr size_t sizeY = BLOCK_SIZE;
static constexpr size_t sizeZ = BLOCK_SIZE;
......
......@@ -17,6 +17,8 @@ CFLAGS+= -Wwrite-strings -Wmissing-declarations -Wredundant-decls
CFLAGS+= -Wshadow -Woverloaded-virtual -Wuninitialized
CFLAGS+= -Wpedantic -Wno-unused-parameter # does not make much sense with function overloading
OBJ = ../../src/ArgumentParser.o
LIBS =
ifneq (${HDF5_ROOT},)
......@@ -37,11 +39,14 @@ ifeq ("$(hdf5precision)","double")
endif
ifeq ("$(nonuniform)","yes")
CFLAGS += -DCUBISM_TEST__NONUNIFORM
CFLAGS += -DCUBISM_TEST_NONUNIFORM
endif
all: testDumpsMPI.cpp
$(CC) $(CFLAGS) -o testDumpsMPI testDumpsMPI.cpp $(LIBS) -lhdf5
all: testDumpsMPI.cpp $(OBJ)
$(CC) $(CFLAGS) -o testDumpsMPI testDumpsMPI.cpp $(OBJ) $(LIBS) -lhdf5
%.o: %.cpp
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f testDumpsMPI *.o *.h5 *.xmf *.bin *.zbin
......@@ -11,6 +11,7 @@
#include "Cubism/Grid.h"
#include "Cubism/GridMPI.h"
#include "Cubism/MeshMap.h"
#include "Cubism/MeshKernels.h"
#define CUBISM_USE_HDF
#include "Cubism/HDF5Dumper.h"
......
......@@ -16,6 +16,7 @@ CFLAGS+= -Wwrite-strings -Wmissing-declarations -Wredundant-decls
CFLAGS+= -Wshadow -Woverloaded-virtual -Wuninitialized
CFLAGS+= -Wpedantic -Wno-unused-parameter # does not make much sense with function overloading
OBJ = ../../src/ArgumentParser.o
.PHONY: all clean
......@@ -29,8 +30,11 @@ ifeq ("$(nonuniform)","yes")
CFLAGS += -DCUBISM_TEST_NONUNIFORM
endif
all: testSynchronizerMPI.cpp
$(CC) $(CFLAGS) -o testSynchronizerMPI testSynchronizerMPI.cpp
all: testSynchronizerMPI.cpp $(OBJ)
$(CC) $(CFLAGS) -o testSynchronizerMPI testSynchronizerMPI.cpp $(OBJ)
%.o: %.cpp
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f testSynchronizerMPI *.o
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