Skip to content

Commit

Permalink
Add a simple C++ program illustrating generation 3d turbulent volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnikolic committed Feb 6, 2009
1 parent 964db50 commit 0bdc29f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .bzrignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@ CVS
./oof/test/Makefile
./bnmin1/test/t_utils
./bnmin1/test/t_utils

./bnlib/test/kvolume
./bnlib/test/Makefile
*.tar.bz2
8 changes: 8 additions & 0 deletions bnlib/test/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin_PROGRAMS = kvolume

kvolume_SOURCES = kvolume.cpp

LDADD=../src/libbnlib.la -lboost_program_options

INCLUDES=-I../src

99 changes: 99 additions & 0 deletions bnlib/test/kvolume.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (2009) Bojan Nikolic <[email protected]>
//
// This file is part of BNLib
// BNLIB is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// BNLIB is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with BNLIB. If not, see <http://www.gnu.org/licenses/>.
//
// Comments regarding this example welcome at:
// Bojan Nikolic <[email protected]>

#include <iostream>
#include <boost/program_options.hpp>

#include "../src/kolmog/kolmogorov_3d.hxx"
#include "../src/bnrandom.hxx"

int main(int argc, char* argv[])
{
using namespace boost::program_options;

options_description desc("Allowed options");
desc.add_options()
("nx", value<size_t>(),
"Number of pixels in the X direction")
("ny", value<size_t>(),
"Number of pixels in the Y direction")
("nz", value<size_t>(),
"Number of pixels in the Z direction")
("help", "Produce this help message");

positional_options_description p;
p.add("nx", 1);
p.add("ny", 1);
p.add("nz", 1);

variables_map vm;
store(command_line_parser(argc, argv).
options(desc).positional(p).run(),
vm);
notify(vm);

if (vm.count("help"))
{
std::cout<<"Generate a Kolmogorov phase volume and write it out standard output"
<<std::endl
<<"This program is part of BNLib"<<std::endl
<<"GPL license -- you have the right to the source code. See COPYING"<<std::endl
<<std::endl
<<"The dimensions of the volume must each be of 2^n+1 type and nx >= ny >= nz"<<std::endl
<<"The output is written as a contiugous sequence of IEEE double-precision floating point values"<<std::endl
<<"The endianity is defined by your computer"<<std::endl
<<"The output is binary and will go to standard output; therefore it is best"<<std::endl
<<"to redirect to a file"<<std::endl
<<std::endl
<<"For example:"<<std::endl
<<" ./kvolume 1025 257 129 > phasevolume.dat"<<std::endl
<<std::endl
<<std::endl
<<std::endl
<<desc;
}
else
{
using namespace BNLib;

const size_t nx = vm["nx"].as<size_t>();
const size_t ny = vm["ny"].as<size_t>();
const size_t nz = vm["nz"].as<size_t>();

const size_t totalsize=nx*ny*nz;

double * cube = new double[totalsize];
BNLib::NormDistZM dist(1.0);

Kolmogorov3D(cube,
nx,
ny,
nz,
dist,
KInitialEFB & KBalancedIters & KEdgeBalanced);

std::cout.write((char *)cube,
sizeof(double)*totalsize);

delete[] cube;
}
}



0 comments on commit 0bdc29f

Please sign in to comment.