diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..3f8f2d3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,13 @@ +### There's a *broken feature* in MMSP +- Bug appears in {file or program} +- Encountered running on {CPU} and {accelerator} using {OS} with {relevant software} +- The expected behavior is +- The observed behavior is + +### There's a *missing feature* in MMSP +- The gap is in {file or program} +- It deserves attention because +- A possible approach is + +### There's a *confusing feature* in MMSP +- Join the conversation on [gitter](https://gitter.im/mesoscale/mmsp)! diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..cdca1e1 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,7 @@ +The proposed changes are intended to {summary of intent}. + +This is achieved by {description of method}. + +Fixes #, Addresses # + +The modified code may have unintended consequences in {areas of concern}. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0402e5a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,130 @@ +# Contributing to [MMSP: The Mesoscale Microstructure Simulation Project][_mmsp] + +Thank you for spending some time with MMSP. We sincerely appreciate your +interest, and hope you will consider contributing to the documentation, +source code, and community at large. This code is open-source, and we really +appreciate input from the community. There are several ways you can contribute, +including editing or adding documentation, writing tutorials, submitting bug +reports, requesting new features, and writing code to incorporate. If you'd like +to help out, please do! + +If you're looking for support or guidance, please visit our [Gitter chat][_gitter] +to talk with the developers and community members, or send an e-mail to +. + +## Ground Rules + +- Help us to maintain a considerate and supportive community by reading and + enforcing the [Code of Conduct][_conduct]. Be nice to newcomers. +- Promote clean code by ensuring your code and documentation build with neither + warnings nor errors using compiler flags equivalent to [GCC's][_gcc] + `-Wall -pedantic`. +- Engage with the community by creating [issues][_issue] for changes or + enhancements you'd like to make. Discuss ideas the open and get feedback. +- Maximize reusability by keeping code simple. Program in C if possible, and + generally follow the [Google C++ Style Guide][_goog]. Avoid creating new + classes if possible. +- Document new functions and classes with [Doxygen][_doxy]-compatible comments + in the source code. + +## Getting Started + +Interested in helping, but unsure where to start? Consider proofreading the PDF +documentation and reporting or fixing errors! There's bound to be a typo in +there. Or look through the existing [issues][_issue] for fixes or enhancements +you're interested in. The number of comments on an issue can indicate its level +of difficulty, as well as the impact closing it will have. + +If you're brand new to open source, welcome! You might benefit from the +[GitHub Help Pages][_ghhelp] and a [tutorial][_tut]. + +## Branching Workflow + +[MMSP][_mmsp] uses [git][_git] version control with a [branching workflow][_branch], +summarized below. Following this workflow ensures a pristine `master` branch +that remains synchronized, and allows collaborators to quickly and easily review +contributions for content and quality. + +The core mantra is ***never commit to `master`***. On [mesoscale/mmsp][_mmsp], +`master` is the rolling release branch, and code must only be merged into it +following [continuous integration][_ci] testing, code review, and discussion. + +Changes are made on *branches*, using `master` as the trunk. Ideally, a branch +is created based on an [issue][_issue], which captures a *feature* or *hotfix* +to MMSP. To paraphrase illustrations of more involved workflows, a simple +branching model for MMSP looks like the following, with `B` indicating a branch +named `___`, `M` a commit with message `"___"`, `?` a pull request, and `D` +deletion of a branch. Note that branches are numbered sequentially, using the +number of the [issue][_issue] outlining the missing or broken functionality to +be patched. + +``` + mesoscale/ origin/ origin/ + master hotfix feature hotfix feature + : + | + +-----------------------------------------B issue4 + | | + +--------------------------B bug5 M "create function" + | M "missing ;" M "update docs" + | ?----------------+ | + "merge bug5" M---------+ | | + | D D | + +-----------------------------------------M "merge master" + | ?-----------------------+ + | | M "address comments" + | M-----------------------+ + "merge issue4" M-----------------+ | + | D D + : +``` + +## Pull Requests + +*Please neither commit directly to the `master` branch, nor push directly to +mesoscale/mmsp.* + +1. Create a fork of [MMSP][_mmsp] on your personal GitHub account. +2. For obvious changes, such as typos or edits to `.gitignore`, you can edit + your fork directly in the browser, then file a [pull request][_pr]. +3. Most changes begin with an [Issue][_issue]. If one does not exist, create it. +4. On your local machine, use the command line to work on your local fork of + [MMSP][_mmsp]. Create a working branch off of `master`. If you're working, + for example, on issue #42, *function template documentation*: + - [Fork][_ghhelp] mesoscale/mmsp and [clone][_ghhelp] it to your local machine. + Your fork is a `git remote` with the alias `origin` by default. + - `git pull https://github.com/mesoscale/mmsp.git master` to update your + local `master` branch from the main repository. + - `git checkout -b issue42_function-template-documentation master` to + create a local feature branch off of `master`. + - Write your edits, updates, or feature code. + - `git status`, `git add -u`, `git status`, and `git commit`, + in that order, to add your changes. If something is amiss, follow + the terminal guidance to fix it. + - Write a concise commit message (first line), then in-depth commentary below + using the keywords ["Addresses" or "Closes"][_ghkey] where appropriate. + - `git push origin issue42_summarize-usage-in-pseudocode` to push the + *working branch* to your fork on GitHub. +5. Visit GitHub and make the pull request official. Please fill out the pull + request template and assign a reviewer &emdash; `@tkphd` if noone else suits. + +Obvious fixes will be merged quickly. Enhancements may undergo a code review, +which we typically conduct using [reviewable][_review]. + +## Happy Coding! + +[_mmsp]: https://github.com/mesoscale/mmsp +[_branch]: http://nvie.com/posts/a-successful-git-branching-model/ +[_ci]: https://docs.travis-ci.com/ +[_conduct]: https://github.com/mesoscale/mmsp/blob/master/CODE_OF_CONDUCT.md +[_doxy]: https://www.stack.nl/~dimitri/doxygen/manual/docblocks.html +[_gcc]: https://gcc.gnu.org/ +[_ghhelp]: https://help.github.com/ +[_ghkey]: https://help.github.com/articles/closing-issues-using-keywords/ +[_git]: https://git-scm.com/ +[_gitter]: https://gitter.im/mesoscale/mmsp +[_goog]: https://google.github.io/styleguide/cppguide.html +[_issue]: https://github.com/mesoscale/mmsp/issues +[_pr]: https://help.github.com/articles/about-pull-requests/ +[_review]: https://reviewable.io/reviews/mesoscale/mmsp +[_tut]: https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github diff --git a/README.md b/README.md index 8e3e413..a36f4f8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Mesoscale Microstructure Simulation Project ==== [![Build Status](https://travis-ci.org/mesoscale/mmsp.svg?branch=develop)](https://travis-ci.org/mesoscale/mmsp) +[![DOI](https://zenodo.org/badge/19985417.svg)](https://zenodo.org/badge/latestdoi/19985417) The goal of the Mesoscale Microstructure Simulation Project (MMSP) is to provide a simple, consistent, and extensible programming interface for all grid and mesh based microstructure @@ -42,10 +43,11 @@ MMSP is nothing more than a collection of C++ header files that declare a number *MMSP requires:* * Minimal programming experience - * An ISO compliant C++ compiler (e.g. GCC 2.95 or later) - * zlib libraries for data compression (e.g. zlib 1.2.7) - * libpng headers for mmsp2png image generation utility (e.g. libpng12-dev) - * MPI libraries if compiling parallel programs (e.g. Open MPI) + * An ISO compliant C++ compiler (e.g. `gcc` 2.95 or later) + * zlib libraries for data compression (e.g. `zlib` 1.2.7) + * libpng headers for mmsp2png image generation utility (e.g. `libpng12-dev`) + * ParaView VTK headers for VTI and PVD visualization utilities (e.g. `paraview` and `paraview-dev`) + * MPI libraries if compiling parallel programs (e.g. `openmpi`) *Documentation* @@ -53,7 +55,9 @@ The MMSP manual is a work in progress. It is currently the only source for detai *Contact us* -The administrators for the MMSP source code are Jason Gruber (gruberja@gmail.com) and Trevor Keller (trevor.keller@gmail.com). Please do not hesitate to send questions or comments. +The administrators for the MMSP source code are Jason Gruber (gruberja@gmail.com), Trevor Keller (trevor.keller@gmail.com) and Dan Lewis (lucentdan@gmail.com). Please do not hesitate to send questions or comments. Please cite using the following DOI: + +[![DOI](https://zenodo.org/badge/19985417.svg)](https://zenodo.org/badge/latestdoi/19985417) This work was supported in part by the US NSF under award #1056704 through the Metals and Metallic Nanostructures Program, Division of Materials Research. diff --git a/algorithms/generators.cpp b/algorithms/generators.cpp index 437646d..ba15fb1 100644 --- a/algorithms/generators.cpp +++ b/algorithms/generators.cpp @@ -1,4 +1,3 @@ -// generators.cpp // Implementations of methods to initialize MMSP grids #ifndef _GENERATORS_CPP_ #define _GENERATORS_CPP_ @@ -81,9 +80,9 @@ MMSP::vector getPosition(const DistanceVoxel& dv) { template void exact_voronoi(MMSP::grid >& grid, const std::vector > >& seeds) { - int id=0; + int id = 0; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); #endif // Exact Voronoi tessellation from seeds, based on Euclidean distance function. Runtime is O(Nseeds*L*W*H). // seeds must contain every seed from every rank. @@ -193,7 +192,7 @@ void approximate_voronoi(MMSP::grid >& grid, const std::vec #endif int id = 0; #ifdef MPI_VERSION - id = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); #endif // Perform the tessellation, using fast-marching fanciness if (dim == 2) { @@ -400,7 +399,9 @@ void approximate_voronoi(MMSP::grid >& grid, const std::vec } #ifdef DEBUG #ifdef MPI_VERSION - if (MPI::COMM_WORLD.Get_rank()==0) + int id = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &id); + if (id==0) #endif std::cout<<"Completed approximate tessellation ("< >& grid, const std::vec void seedswap(std::vector > >& seeds) { #ifdef MPI_VERSION - int id=MPI::COMM_WORLD.Get_rank(); - int np=MPI::COMM_WORLD.Get_size(); + int id=0, np=0; + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); // Exchange seeds between all processors int send_size=3*seeds[id].size(); // number of integers int* send_buffer = new int[send_size]; // number of integers send_size = seeds_to_buffer(seeds[id], send_buffer); int* seed_sizes = new int[np]; - MPI::COMM_WORLD.Barrier(); - MPI::COMM_WORLD.Allgather(&send_size, 1, MPI_INT, seed_sizes, 1, MPI_INT); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Allgather(&send_size, 1, MPI_INT, seed_sizes, 1, MPI_INT, MPI_COMM_WORLD); int total_size=0; for (int i=0; i > >& seeds) delete [] seed_block; seed_block=NULL; int vote=1; int total_procs=0; - MPI::COMM_WORLD.Barrier(); - MPI::COMM_WORLD.Allreduce(&vote, &total_procs, 1, MPI_INT, MPI_SUM); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Allreduce(&vote, &total_procs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); #ifdef DEBUG if (id==0) std::cout<<"Synchronized "< > >& seeds) template void seeds_from_poisson_process(const int x0[dim], const int x1[dim], const int g0[dim], const int g1[dim], const int& nseeds, std::vector > >& seeds) { - int id=0; - int np=1; + int id=0, np=1; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); - np=MPI::COMM_WORLD.Get_size(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif std::vector > local_seeds; // blank for now seeds.clear(); @@ -482,7 +483,7 @@ void seeds_to_file(const int g0[dim], const int g1[dim], const std::vector void seeds_from_file(const int x0[dim], const int x1[dim], const int g0[dim], const int g1[dim], const char* seedfilename, std::vector > >& seeds) { - int id=0; - int np=1; + int id=0, np=1; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); - np=MPI::COMM_WORLD.Get_size(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif std::ifstream input(seedfilename); if (!input) { @@ -547,11 +547,10 @@ void seeds_from_file(const int x0[dim], const int x1[dim], const int g0[dim], co template void honeycomb_seeds(const int x0[dim], const int x1[dim], const int g0[dim], const int g1[dim], const int a, std::vector > >& seeds) { - int id=0; - int np=1; + int id=0, np=1; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); - np=MPI::COMM_WORLD.Get_size(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif std::vector > local_seeds; // blank for now seeds.clear(); @@ -597,7 +596,7 @@ void tessellate(MMSP::grid >& grid, const int& nseeds) { approximate_voronoi(grid, seeds); #else exact_voronoi(grid, seeds); - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif } // tessellate diff --git a/algorithms/tessellate.hpp b/algorithms/tessellate.hpp index bdd529d..0d5a073 100644 --- a/algorithms/tessellate.hpp +++ b/algorithms/tessellate.hpp @@ -114,7 +114,8 @@ namespace MMSP { #ifdef MPI_VERSION template void exact_voronoi(MMSP::grid >& grid, const std::vector > >& seeds) { - int id=MPI::COMM_WORLD.Get_rank(); + int id=0; + MPI_Comm_rank(MPI_COMM_WORLD, &id); // Exact Voronoi tessellation from seeds, based on Euclidean distance function. Runtime is O(Nseeds*L*W*H). // seeds must contain every seed from every rank. #ifdef DEBUG @@ -223,8 +224,9 @@ void approximate_voronoi(MMSP::grid >& grid, const std::vector >& grid, const std::vector >& grid, const std::vector void tessellate(const std::vector >& local_seeds, std::vector > >& seeds, MMSP::grid >& grid) { - int id=0; - int np=1; + int id=0, np=1; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); - np=MPI::COMM_WORLD.Get_size(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif #ifndef MPI_VERSION @@ -455,16 +459,16 @@ void tessellate(const std::vector >& local_seeds, std::vector< int* send_buffer = new int[send_size]; // number of integers send_size = seeds_to_buffer(local_seeds, send_buffer); int* seed_sizes = new int[np]; - MPI::COMM_WORLD.Barrier(); - MPI::COMM_WORLD.Allgather(&send_size, 1, MPI_INT, seed_sizes, 1, MPI_INT); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Allgather(&send_size, 1, MPI_INT, seed_sizes, 1, MPI_INT, MPI_COMM_WORLD); int total_size=0; for (int i=0; i >& local_seeds, std::vector< delete [] seed_block; seed_block=NULL; int vote=1; int total_procs=0; - MPI::COMM_WORLD.Barrier(); - MPI::COMM_WORLD.Allreduce(&vote, &total_procs, 1, MPI_INT, MPI_SUM); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Allreduce(&vote, &total_procs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (id==0) std::cout<<"Synchronized "< >& local_seeds, std::vector< approximate_voronoi(grid, seeds); #else exact_voronoi(grid, seeds); - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); total_procs=0; - MPI::COMM_WORLD.Allreduce(&vote, &total_procs, 1, MPI_INT, MPI_SUM); + MPI_Allreduce(&vote, &total_procs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); #endif } // tessellate @@ -497,7 +501,7 @@ template void seeds_from_prng(const MMSP::grid >& grid, const int& nseeds, std::vector >& local_seeds) { int id=0; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); #endif unsigned long int pseudorand_seed = time(NULL); @@ -524,7 +528,7 @@ template void seeds_from_file(const MMSP::grid >& grid, const std::string& seed_filename, std::vector >& local_seeds) { int id=0; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &id); #endif if (id == 0) std::cout << "Reading seeds from " << seed_filename << std::endl; @@ -565,7 +569,7 @@ template void tessellate(MMSP::grid >& grid, const int& nseeds) { int np=1; #ifdef MPI_VERSION - np=MPI::COMM_WORLD.Get_size(); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif std::vector > local_seeds; // blank for now std::vector > > seeds; @@ -583,7 +587,7 @@ template void tessellate(MMSP::grid >& grid, const std::string& seed_filename) { int np=1; #ifdef MPI_VERSION - np=MPI::COMM_WORLD.Get_size(); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif std::vector > local_seeds; // blank for now std::vector > > seeds; diff --git a/doc/MMSP.chapter2.tex b/doc/MMSP.chapter2.tex index 7ad2f12..961b680 100644 --- a/doc/MMSP.chapter2.tex +++ b/doc/MMSP.chapter2.tex @@ -42,7 +42,18 @@ \section{Installation} Mac OS users will follow much of the same procedure as Linux users, so it is advisible to read the previous section on Linux installation. For those uninitiated, or who have never had any previous reason to use it, the {\tt Terminal} application can be found under {\tt Applications/Utilities}. Again, all steps described above for Linux installation should apply here as well. \paragraph{Windows} -For those who insist on using Windows, it is still possible to use \MMSP. The preferred way to do this is to use the \href{http://www.cygwin.com}{cygwin} environment. To use {\tt cygwin} with \MMSP, it is necessary that appropriate packages, such as {\tt gcc} (the GNU compiler) and {\tt make} (the GNU make utility), have been installed. These are optional packages that must be chosen manually during installation. If {\tt cygwin} has been installed properly, \MMSP\ may be installed by following the steps described above for Linux installations. +For those who insist on using Windows, it is still possible to use \MMSP. The preferred way to do this is to use the \href{http://www.cygwin.com}{cygwin} environment. To use {\tt cygwin} with \MMSP, it is necessary that appropriate packages have been installed. The following packages are required to run \MMSP\ : + +\begin{itemize} + \item \textbf{gcc-g++} + \item \textbf{make} + \item \textbf{zlib-devel} + \item \textbf{libpng-devel} + \item \textbf{openmpi} + \item \textbf{libopenmpi-devel} +\end{itemize} + +If {\tt cygwin} has been installed properly, \MMSP\ may be installed by following the steps described above for Linux installations. It is also possible to compile \MMSP\ source code within a code development environment such as Visual Studio, however, \MMSP\ code is typically so simple that any code management beyond command line or makefile compilation is only a hinderance. diff --git a/doc/MMSP.chapter3.tex b/doc/MMSP.chapter3.tex index f2dc693..8a05a81 100644 --- a/doc/MMSP.chapter3.tex +++ b/doc/MMSP.chapter3.tex @@ -34,7 +34,7 @@ \subsection{The {\tt Hello MMSP!} program} MMSP::Finalize(); \end{verbatim} \end{shadebox} -What do these lines do? For single processor programs, they do absolutely nothing -- they could actually be removed without any consequences. However, for programs that use the message passing interface (MPI), they act as wrappers for the similarly named {\tt MPI::Init} and {\tt MPI::Finalize} commands. It's useful to include them here because they'll allow us to write programs that may be compiled for both single or multiple processor environments. +What do these lines do? For single processor programs, they do absolutely nothing -- they could actually be removed without any consequences. However, for programs that use the message passing interface (MPI), they act as wrappers for the similarly named {\tt MPI_Init} and {\tt MPI_Finalize} commands. It's useful to include them here because they'll allow us to write programs that may be compiled for both single or multiple processor environments. Programmers familiar with {\tt c++} will notice that there's obviously some \MMSP\ namespace being used here. For those less familiar, namespaces are a somewhat recent addition to {\tt c++} that are used as a means of avoiding naming conflicts. We can avoid using namespace resolution so frequently if we use an appropriate {\tt using} statement, i.e. \begin{shadebox} diff --git a/doc/MMSP.manual.pdf b/doc/MMSP.manual.pdf index 2a57802..66d1d25 100644 Binary files a/doc/MMSP.manual.pdf and b/doc/MMSP.manual.pdf differ diff --git a/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/Makefile b/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/Makefile index 7483eed..e08b00d 100644 --- a/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/Makefile +++ b/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program graingrowth: graingrowth.cpp diff --git a/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/graingrowth.cpp b/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/graingrowth.cpp index 7c3c341..31b25a6 100644 --- a/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/graingrowth.cpp +++ b/examples/coarsening/grain_growth/anisotropic/Monte_Carlo/graingrowth.cpp @@ -64,7 +64,7 @@ template void update(grid& mcGrid, int steps) { int rank = 0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(mcGrid); @@ -181,7 +181,7 @@ template void update(grid& mcGrid, int steps) // This particular algorithm requires that srand() be called here. unsigned long seed=time(NULL); #ifdef MPI_VERSION - MPI::COMM_WORLD.Bcast(&seed, 1, MPI_UNSIGNED_LONG, 0); + MPI_Bcast(&seed, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); #endif srand(seed); // Also, time(NULL)+rank is an INCORRECT seed for this purpose. @@ -368,7 +368,7 @@ template void update(grid& mcGrid, int steps) } // hh #ifdef MPI_VERSION - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif ghostswap(mcGrid, sublattice); // once looped over a "color", ghostswap. }//loop over sublattice diff --git a/examples/coarsening/grain_growth/anisotropic/phase_field/Makefile b/examples/coarsening/grain_growth/anisotropic/phase_field/Makefile index 97baf9e..e08b00d 100644 --- a/examples/coarsening/grain_growth/anisotropic/phase_field/Makefile +++ b/examples/coarsening/grain_growth/anisotropic/phase_field/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program graingrowth: graingrowth.cpp diff --git a/examples/coarsening/grain_growth/anisotropic/phase_field/graingrowth.cpp b/examples/coarsening/grain_growth/anisotropic/phase_field/graingrowth.cpp index 131eee5..cb9c6c2 100644 --- a/examples/coarsening/grain_growth/anisotropic/phase_field/graingrowth.cpp +++ b/examples/coarsening/grain_growth/anisotropic/phase_field/graingrowth.cpp @@ -95,7 +95,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/coarsening/grain_growth/anisotropic/sparsePF/Makefile b/examples/coarsening/grain_growth/anisotropic/sparsePF/Makefile index 97baf9e..e08b00d 100644 --- a/examples/coarsening/grain_growth/anisotropic/sparsePF/Makefile +++ b/examples/coarsening/grain_growth/anisotropic/sparsePF/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program graingrowth: graingrowth.cpp diff --git a/examples/coarsening/grain_growth/anisotropic/sparsePF/graingrowth.cpp b/examples/coarsening/grain_growth/anisotropic/sparsePF/graingrowth.cpp index 105130d..0aa9b30 100644 --- a/examples/coarsening/grain_growth/anisotropic/sparsePF/graingrowth.cpp +++ b/examples/coarsening/grain_growth/anisotropic/sparsePF/graingrowth.cpp @@ -88,7 +88,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif double dt = 0.01; double width = 8.0; diff --git a/examples/coarsening/grain_growth/isotropic/Monte_Carlo/Makefile b/examples/coarsening/grain_growth/isotropic/Monte_Carlo/Makefile index 7483eed..e08b00d 100644 --- a/examples/coarsening/grain_growth/isotropic/Monte_Carlo/Makefile +++ b/examples/coarsening/grain_growth/isotropic/Monte_Carlo/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program graingrowth: graingrowth.cpp diff --git a/examples/coarsening/grain_growth/isotropic/Monte_Carlo/graingrowth.cpp b/examples/coarsening/grain_growth/isotropic/Monte_Carlo/graingrowth.cpp index 9513571..15d82de 100644 --- a/examples/coarsening/grain_growth/isotropic/Monte_Carlo/graingrowth.cpp +++ b/examples/coarsening/grain_growth/isotropic/Monte_Carlo/graingrowth.cpp @@ -63,7 +63,7 @@ template void update(grid& mcGrid, int steps) { int rank = 0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(mcGrid); @@ -180,7 +180,7 @@ template void update(grid& mcGrid, int steps) // This particular algorithm requires that srand() be called here. unsigned long seed=time(NULL); #ifdef MPI_VERSION - MPI::COMM_WORLD.Bcast(&seed, 1, MPI_UNSIGNED_LONG, 0); + MPI_Bcast(&seed, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); #endif srand(seed); // Also, time(NULL)+rank is an INCORRECT seed for this purpose. @@ -364,7 +364,7 @@ template void update(grid& mcGrid, int steps) } // hh #ifdef MPI_VERSION - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif ghostswap(mcGrid, sublattice); // once looped over a "color", ghostswap. }//loop over sublattice diff --git a/examples/coarsening/grain_growth/isotropic/phase_field/Makefile b/examples/coarsening/grain_growth/isotropic/phase_field/Makefile index 97baf9e..e08b00d 100644 --- a/examples/coarsening/grain_growth/isotropic/phase_field/Makefile +++ b/examples/coarsening/grain_growth/isotropic/phase_field/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program graingrowth: graingrowth.cpp diff --git a/examples/coarsening/grain_growth/isotropic/phase_field/graingrowth.cpp b/examples/coarsening/grain_growth/isotropic/phase_field/graingrowth.cpp index f8eff4c..d7bb2b2 100644 --- a/examples/coarsening/grain_growth/isotropic/phase_field/graingrowth.cpp +++ b/examples/coarsening/grain_growth/isotropic/phase_field/graingrowth.cpp @@ -74,7 +74,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); @@ -138,7 +138,7 @@ TEST(grid1DTest, Finite) { #ifdef MPI_VERSION for (int i=0; i<2; i++) { double myLen(length[i]); - MPI::COMM_WORLD.Allreduce(&myLen,&length[i],1,MPI_DOUBLE,MPI_SUM); + MPI_Allreduce(&myLen,&length[i],1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } #endif for (int n=0; n void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/coarsening/ostwald_ripening/isotropic/phase_field/Makefile b/examples/coarsening/ostwald_ripening/isotropic/phase_field/Makefile index 750204f..25f52c3 100644 --- a/examples/coarsening/ostwald_ripening/isotropic/phase_field/Makefile +++ b/examples/coarsening/ostwald_ripening/isotropic/phase_field/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program ostwald: ostwald.cpp diff --git a/examples/coarsening/ostwald_ripening/isotropic/phase_field/ostwald.cpp b/examples/coarsening/ostwald_ripening/isotropic/phase_field/ostwald.cpp index 2857466..6182ca9 100644 --- a/examples/coarsening/ostwald_ripening/isotropic/phase_field/ostwald.cpp +++ b/examples/coarsening/ostwald_ripening/isotropic/phase_field/ostwald.cpp @@ -57,7 +57,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/Makefile b/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/Makefile index 80ba9c8..c1c5d68 100644 --- a/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/Makefile +++ b/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program zener: zener.cpp diff --git a/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/zener.cpp b/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/zener.cpp index b534ba1..0ff458a 100644 --- a/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/zener.cpp +++ b/examples/coarsening/zener_pinning/anisotropic/Monte_Carlo/zener.cpp @@ -91,7 +91,7 @@ template void update(grid& mcGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(mcGrid); diff --git a/examples/coarsening/zener_pinning/anisotropic/phase_field/Makefile b/examples/coarsening/zener_pinning/anisotropic/phase_field/Makefile index c9247f6..33ad0c3 100644 --- a/examples/coarsening/zener_pinning/anisotropic/phase_field/Makefile +++ b/examples/coarsening/zener_pinning/anisotropic/phase_field/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program zener: zener.cpp diff --git a/examples/coarsening/zener_pinning/anisotropic/phase_field/zener.cpp b/examples/coarsening/zener_pinning/anisotropic/phase_field/zener.cpp index 57456d9..e694b15 100644 --- a/examples/coarsening/zener_pinning/anisotropic/phase_field/zener.cpp +++ b/examples/coarsening/zener_pinning/anisotropic/phase_field/zener.cpp @@ -106,7 +106,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/coarsening/zener_pinning/anisotropic/sparsePF/Makefile b/examples/coarsening/zener_pinning/anisotropic/sparsePF/Makefile index c9247f6..33ad0c3 100644 --- a/examples/coarsening/zener_pinning/anisotropic/sparsePF/Makefile +++ b/examples/coarsening/zener_pinning/anisotropic/sparsePF/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program zener: zener.cpp diff --git a/examples/coarsening/zener_pinning/anisotropic/sparsePF/zener.cpp b/examples/coarsening/zener_pinning/anisotropic/sparsePF/zener.cpp index 1e828e1..237ed7d 100644 --- a/examples/coarsening/zener_pinning/anisotropic/sparsePF/zener.cpp +++ b/examples/coarsening/zener_pinning/anisotropic/sparsePF/zener.cpp @@ -100,7 +100,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/Makefile b/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/Makefile index c9247f6..33ad0c3 100644 --- a/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/Makefile +++ b/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program zener: zener.cpp diff --git a/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/zener.cpp b/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/zener.cpp index 775a0dd..31dfc59 100644 --- a/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/zener.cpp +++ b/examples/coarsening/zener_pinning/isotropic/Monte_Carlo/zener.cpp @@ -90,7 +90,7 @@ template void update(grid& mcGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(mcGrid); diff --git a/examples/coarsening/zener_pinning/isotropic/phase_field/Makefile b/examples/coarsening/zener_pinning/isotropic/phase_field/Makefile index c9247f6..33ad0c3 100644 --- a/examples/coarsening/zener_pinning/isotropic/phase_field/Makefile +++ b/examples/coarsening/zener_pinning/isotropic/phase_field/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program zener: zener.cpp diff --git a/examples/coarsening/zener_pinning/isotropic/phase_field/zener.cpp b/examples/coarsening/zener_pinning/isotropic/phase_field/zener.cpp index 27cfa08..4427fe1 100644 --- a/examples/coarsening/zener_pinning/isotropic/phase_field/zener.cpp +++ b/examples/coarsening/zener_pinning/isotropic/phase_field/zener.cpp @@ -105,7 +105,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/coarsening/zener_pinning/isotropic/sparsePF/Makefile b/examples/coarsening/zener_pinning/isotropic/sparsePF/Makefile index c9247f6..33ad0c3 100644 --- a/examples/coarsening/zener_pinning/isotropic/sparsePF/Makefile +++ b/examples/coarsening/zener_pinning/isotropic/sparsePF/Makefile @@ -8,8 +8,8 @@ incdir = ../../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program zener: zener.cpp diff --git a/examples/coarsening/zener_pinning/isotropic/sparsePF/zener.cpp b/examples/coarsening/zener_pinning/isotropic/sparsePF/zener.cpp index d8d1c0e..dfe8a07 100644 --- a/examples/coarsening/zener_pinning/isotropic/sparsePF/zener.cpp +++ b/examples/coarsening/zener_pinning/isotropic/sparsePF/zener.cpp @@ -99,7 +99,7 @@ template void update(grid >& oldGrid, int st { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/differential_equations/elliptic/Poisson/Makefile b/examples/differential_equations/elliptic/Poisson/Makefile index a509277..d288be5 100644 --- a/examples/differential_equations/elliptic/Poisson/Makefile +++ b/examples/differential_equations/elliptic/Poisson/Makefile @@ -8,7 +8,7 @@ incdir = ../../../../include compiler = g++ pcompiler = mpic++ flags = -O3 -Wall -I $(incdir) -pflags = $(flags) -include mpi.h +pflags = $(flags) -fpermissive -include mpi.h # the program poisson: poisson.cpp diff --git a/examples/phase_transitions/allen-cahn/Makefile b/examples/phase_transitions/allen-cahn/Makefile index 39fbc09..5b66949 100644 --- a/examples/phase_transitions/allen-cahn/Makefile +++ b/examples/phase_transitions/allen-cahn/Makefile @@ -8,8 +8,8 @@ incdir = ../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program allen-cahn: allen-cahn.cpp diff --git a/examples/phase_transitions/allen-cahn/allen-cahn.cpp b/examples/phase_transitions/allen-cahn/allen-cahn.cpp index d3185f4..21e30d4 100644 --- a/examples/phase_transitions/allen-cahn/allen-cahn.cpp +++ b/examples/phase_transitions/allen-cahn/allen-cahn.cpp @@ -48,7 +48,7 @@ template void update(grid& oldGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/phase_transitions/cahn-hilliard/convex_splitting/Makefile b/examples/phase_transitions/cahn-hilliard/convex_splitting/Makefile index b553b94..a2b81a0 100644 --- a/examples/phase_transitions/cahn-hilliard/convex_splitting/Makefile +++ b/examples/phase_transitions/cahn-hilliard/convex_splitting/Makefile @@ -9,8 +9,8 @@ incdir = ../../../../include # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -DVANILLA -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -DVANILLA -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program cahn-hilliard: cahn-hilliard.cpp diff --git a/examples/phase_transitions/cahn-hilliard/convex_splitting/cahn-hilliard.cpp b/examples/phase_transitions/cahn-hilliard/convex_splitting/cahn-hilliard.cpp index fa6fdb0..eabe0f3 100644 --- a/examples/phase_transitions/cahn-hilliard/convex_splitting/cahn-hilliard.cpp +++ b/examples/phase_transitions/cahn-hilliard/convex_splitting/cahn-hilliard.cpp @@ -180,7 +180,7 @@ template void reportEnergy(const MMSP::grid > { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif double dV = 1.0; @@ -205,8 +205,8 @@ template void reportEnergy(const MMSP::grid > #ifdef MPI_VERSION double localEnergy = energy; double localMass = mass; - MPI::COMM_WORLD.Reduce(&localEnergy, &energy, 1, MPI_DOUBLE, MPI_SUM, 0); - MPI::COMM_WORLD.Reduce(&localMass, &mass, 1, MPI_DOUBLE, MPI_SUM, 0); + MPI_Reduce(&localEnergy, &energy, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&localMass, &mass, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); #endif //if (rank==0) // std::cout<<'0'<<'\t'< >& oldGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); @@ -296,7 +296,7 @@ void update(grid >& oldGrid, int steps) double gridSize = static_cast(nodes(oldGrid)); #ifdef MPI_VERSION double localGridSize = gridSize; - MPI::COMM_WORLD.Allreduce(&localGridSize, &gridSize, 1, MPI_DOUBLE, MPI_SUM); + MPI_Allreduce(&localGridSize, &gridSize, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); #endif double lapWeight = 0.0; @@ -416,9 +416,9 @@ void update(grid >& oldGrid, int steps) #ifdef MPI_VERSION double localResidual=residual; - MPI::COMM_WORLD.Allreduce(&localResidual, &residual, 1, MPI_DOUBLE, MPI_SUM); + MPI_Allreduce(&localResidual, &residual, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); double localNormB=normB; - MPI::COMM_WORLD.Allreduce(&localNormB, &normB, 1, MPI_DOUBLE, MPI_SUM); + MPI_Allreduce(&localNormB, &normB, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); #endif residual = sqrt(residual/normB)/(2.0*gridSize); @@ -429,7 +429,8 @@ void update(grid >& oldGrid, int steps) if (iter==max_iter) { if (rank==0) std::cerr<<" Solver stagnated on step "< void update(grid >& oldGrid, int steps) { - int id=0; - int np=1; - static int iterations=1; + int id = 0; + static int iterations = 1; #ifdef MPI_VERSION - id=MPI::COMM_WORLD.Get_rank(); - np=MPI::COMM_WORLD.Get_size(); + int np; + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); #endif ghostswap(oldGrid); - static grid refGrid(oldGrid,0); // constructor copies only field 0 grid > newGrid(oldGrid); - - double dt=5e-5; // time-step - double theta=0.; // angle relative to lab frame - double c=0.02; // degree of anisotropy - double N=6.; // symmetry - double alpha=0.015; // gradient-energy coefficient - double tau=3e-4; // time normalization constant - double k1=0.9; - double k2=20.; - double DiffT=2.25; // thermal diffusivity - double CFL=tau/(2*alpha*alpha*(1./pow(dx(oldGrid,0),2)+1./pow(dx(oldGrid,1),2))); // Courant-Friedrich-Lewy condition on dt + static grid refGrid(oldGrid, 0); // create scalar- from vector-valued grid + for (int i = 0; i < nodes(refGrid); i++) // initialize values for refGrid + refGrid(i) = oldGrid(i)[0]; + + double dt = 5e-5; // time-step + const double theta = 0.; // angle relative to lab frame + const double c = 0.02; // degree of anisotropy + const double N = 6.; // symmetry + const double alpha = 0.015; // gradient-energy coefficient + const double tau = 3e-4; // time normalization constant + const double k1 = 0.9; + const double k2 = 20.; + const double DiffT = 2.25; // thermal diffusivity + const double CFL = tau/(2*alpha*alpha*(1./pow(dx(oldGrid,0),2)+1./pow(dx(oldGrid,1),2))); // Courant-Friedrich-Lewy condition on dt if (dt>0.5*CFL) { - if (id==0) std::cout<<"dt="<0.5*CFL) dt*=3./4; - if (id==0) std::cout< 0.5*CFL) + dt *= 3./4; + if (id == 0) + std::cout << dt << "." << std::endl; } - std::cout.precision(2); - int minus=0; - int plus=0; - for (int step=0; step > Dgradphi(oldGrid); - for (int i=0; i x=position(oldGrid,i); + for (int i = 0; i < nodes(oldGrid); i++) { + vector x = position(oldGrid,i); + const T& center = oldGrid(x)[0]; // calculate grad(phi) vector gradphi(dim,0.); // (0,0) - for (int d=0; d x = position(oldGrid,i); + const vector& oldX = oldGrid(x); + const vector& dgpX = Dgradphi(x); + vector& newX = newGrid(x); // Update phase field T divDgradphi = 0.; - for (int d=0; d old=oldGrid(i); - T m_phi=old[0]-0.5-(k1/M_PI)*atan(k2*old[1]); - // Semi-implicit scheme per Warren 2003 - if (m_phi>0) { - newGrid(x)[0] = ((m_phi+tau/dt)*old[0]+divDgradphi)/(tau/dt+old[0]*m_phi); - } else { - newGrid(x)[0] = (old[0]*tau/dt+divDgradphi)/(tau/dt-(1.-old[0])*m_phi); + for (int d = 0; d < dim; d++) { + x[d]--; + const T& left = Dgradphi(x)[d]; + x[d]++; + divDgradphi += (dgpX[d] - left) / dx(oldGrid,d); } - // Fully explicit forward-Euler discretization - //newGrid(x)[0] = oldGrid(i)[0] + dt*dphidt/tau; + + // Semi-implicit scheme per Warren 2003, Eqn. A.21 + T m_phi = oldX[0]-0.5-(k1/M_PI)*atan(k2*oldX[1]); + if (m_phi>0) + newX[0] = ((m_phi+tau/dt)*oldX[0]+divDgradphi)/(tau/dt+oldX[0]*m_phi); + else + newX[0] = (oldX[0]*tau/dt+divDgradphi)/(tau/dt-(1.-oldX[0])*m_phi); // Update undercooling field - T lapT=0; - for (int d=0; d void update(grid& oldGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(oldGrid); diff --git a/examples/statistical_mechanics/Heisenberg/Makefile b/examples/statistical_mechanics/Heisenberg/Makefile index 50d5bc7..cd7314a 100644 --- a/examples/statistical_mechanics/Heisenberg/Makefile +++ b/examples/statistical_mechanics/Heisenberg/Makefile @@ -8,8 +8,8 @@ incdir = ../../../include/ # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program heisenberg: heisenberg.cpp diff --git a/examples/statistical_mechanics/Heisenberg/heisenberg.cpp b/examples/statistical_mechanics/Heisenberg/heisenberg.cpp index b8d8056..fd1a5d4 100644 --- a/examples/statistical_mechanics/Heisenberg/heisenberg.cpp +++ b/examples/statistical_mechanics/Heisenberg/heisenberg.cpp @@ -63,7 +63,7 @@ template void update(grid >& spinGrid, int s { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(spinGrid); diff --git a/examples/statistical_mechanics/Ising/Makefile b/examples/statistical_mechanics/Ising/Makefile index dd7fa6f..f2e55d5 100644 --- a/examples/statistical_mechanics/Ising/Makefile +++ b/examples/statistical_mechanics/Ising/Makefile @@ -8,8 +8,8 @@ incdir = ../../../include/ # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program ising: ising.cpp diff --git a/examples/statistical_mechanics/Ising/ising.cpp b/examples/statistical_mechanics/Ising/ising.cpp index 0f89059..7e33a2c 100644 --- a/examples/statistical_mechanics/Ising/ising.cpp +++ b/examples/statistical_mechanics/Ising/ising.cpp @@ -47,7 +47,7 @@ template void update(grid& spinGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(spinGrid); diff --git a/examples/statistical_mechanics/Potts/Makefile b/examples/statistical_mechanics/Potts/Makefile index 44e8a18..e4ef077 100644 --- a/examples/statistical_mechanics/Potts/Makefile +++ b/examples/statistical_mechanics/Potts/Makefile @@ -8,8 +8,8 @@ incdir = ../../../include/ # compilers/flags compiler = g++ pcompiler = mpic++ -flags = -O3 -I $(incdir) -pflags = $(flags) -include mpi.h +flags = -O3 -Wall -I $(incdir) +pflags = $(flags) -fpermissive -include mpi.h # the program potts: potts.cpp diff --git a/examples/statistical_mechanics/Potts/potts.cpp b/examples/statistical_mechanics/Potts/potts.cpp index 7b12245..6ad1d81 100644 --- a/examples/statistical_mechanics/Potts/potts.cpp +++ b/examples/statistical_mechanics/Potts/potts.cpp @@ -48,7 +48,7 @@ template void update(grid& spinGrid, int steps) { int rank=0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif ghostswap(spinGrid); diff --git a/include/MMSP.grid.cpp b/include/MMSP.grid.cpp index 8a5eb17..3fac742 100644 --- a/include/MMSP.grid.cpp +++ b/include/MMSP.grid.cpp @@ -161,20 +161,21 @@ void grid::setup(bool SINGLE) #ifdef MPI_VERSION // get global grid data, set neighbor processors - unsigned int rank = MPI::COMM_WORLD.Get_rank(); - unsigned int np = MPI::COMM_WORLD.Get_size(); + int rank = 0, np = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &np); // if bool SINGLE is set to true, // we generate grid data only on proc 0 if (not SINGLE) { // compute integral factors of "np" int nfac = 0; - for (unsigned int i=1; i<=np; i++) + for (int i=1; i<=np; i++) if ((np / i)*i == np) nfac += 1; int* factors = new int[nfac]; nfac = 0; - for (unsigned int i=1; i<=np; i++) + for (int i=1; i<=np; i++) if ((np / i)*i == np) { factors[nfac] = i; nfac += 1; @@ -208,7 +209,7 @@ void grid::setup(bool SINGLE) } // compute the product of "dim" factors - unsigned int product = 1; + int product = 1; for (int j=0; j::setup(bool SINGLE) resize(data[i], fields); #ifdef MPI_VERSION - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif } @@ -413,7 +414,9 @@ template MMSP::vector grid::position(int i) con template void grid::ghostswap() { #ifdef MPI_VERSION - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Request requests[2]; + MPI_Status statuses[2]; for (int i=0; i void grid::ghostswap() unsigned long recv_size = 0; // Small data transfer: blocking Sendrecv should scale -- but don't plan on it. - MPI::Request requests[2]; - requests[0] = MPI::COMM_WORLD.Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 100); // send number of ghosts - requests[1] = MPI::COMM_WORLD.Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 100); // receive number of ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 100, MPI_COMM_WORLD, &requests[0]); // receive number of ghosts + MPI_Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 100, MPI_COMM_WORLD, &requests[1]);// send number of ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); + char* send_buffer = new char[send_size]; char* recv_buffer = new char[recv_size]; send_size = this->to_buffer(send_buffer, send_min, send_max); // Large data transfer requires non-blocking communication - requests[0] = MPI::COMM_WORLD.Isend(send_buffer, send_size, MPI_CHAR, send_proc, 200); // send ghosts - requests[1] = MPI::COMM_WORLD.Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 200); // receive ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 200, MPI_COMM_WORLD, &requests[0]); // receive ghosts + MPI_Isend(send_buffer, send_size, MPI_CHAR, send_proc, 200, MPI_COMM_WORLD, &requests[1]);// send ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); + this->from_buffer(recv_buffer, recv_min, recv_max); // populate ghost cell data from buffer + delete [] send_buffer; send_buffer=NULL; delete [] recv_buffer; @@ -482,20 +487,20 @@ template void grid::ghostswap() unsigned long recv_size = 0; // Small data transfer: blocking Sendrecv should scale -- but don't plan on it. - MPI::Request requests[2]; - requests[0] = MPI::COMM_WORLD.Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 300); // send number of ghosts - requests[1] = MPI::COMM_WORLD.Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 300); // receive number of incoming ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 300, MPI_COMM_WORLD, &requests[0]); // receive number of incoming ghosts + MPI_Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 300, MPI_COMM_WORLD, &requests[1]);// send number of ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); + char* send_buffer = new char[send_size]; char* recv_buffer = new char[recv_size]; send_size = this->to_buffer(send_buffer, send_min, send_max); // Large data transfer requires non-blocking communication - requests[0] = MPI::COMM_WORLD.Isend(send_buffer, send_size, MPI_CHAR, send_proc, 400); // send ghosts - requests[1] = MPI::COMM_WORLD.Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 400); // receive ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 400, MPI_COMM_WORLD, &requests[0]); // receive ghosts + MPI_Isend(send_buffer, send_size, MPI_CHAR, send_proc, 400, MPI_COMM_WORLD, &requests[1]);// send ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); this->from_buffer(recv_buffer, recv_min, recv_max); // populate ghost cell data from buffer @@ -505,16 +510,19 @@ template void grid::ghostswap() recv_buffer=NULL; } } - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif } template void grid::ghostswap(const int sublattice) // ghostswap for Monte Carlo communiation reduction. { #ifdef MPI_VERSION - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); for (int i=0; i void grid::ghostswap(const int sublattice) unsigned long recv_size = 0; // Small data transfer: blocking Sendrecv should scale -- but don't plan on it. - MPI::Request requests[2]; - requests[0] = MPI::COMM_WORLD.Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 100); // send number of ghosts - requests[1] = MPI::COMM_WORLD.Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 100); // receive number of ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 100, MPI_COMM_WORLD, &requests[0]); // receive number of ghosts + MPI_Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 100, MPI_COMM_WORLD, &requests[1]);// send number of ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); + char* send_buffer = new char[send_size]; char* recv_buffer = new char[recv_size]; send_size = this->to_buffer_save(send_buffer, send_min, send_max); // Large data transfer requires non-blocking communication - requests[0] = MPI::COMM_WORLD.Isend(send_buffer, send_size, MPI_CHAR, send_proc, 200); // send ghosts - requests[1] = MPI::COMM_WORLD.Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 200); // receive ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 200, MPI_COMM_WORLD, &requests[0]); // receive ghosts + MPI_Isend(send_buffer, send_size, MPI_CHAR, send_proc, 200, MPI_COMM_WORLD, &requests[1]);// send ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); this->from_buffer_save(recv_buffer, recv_min, recv_max); // populate ghost cell data from buffer @@ -777,6 +785,9 @@ template void grid::ghostswap(const int sublattice) } if (1) { + MPI_Request requests[2]; + MPI_Status statuses[2]; + // send to processor below and receive from processor above int send_proc = n0[i]; int recv_proc = n1[i]; @@ -1015,21 +1026,20 @@ template void grid::ghostswap(const int sublattice) unsigned long recv_size = 0; // Small data transfer: blocking Sendrecv should scale -- but don't plan on it. - MPI::Request requests[2]; - requests[0] = MPI::COMM_WORLD.Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 300); // send number of ghosts - requests[1] = MPI::COMM_WORLD.Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 300); // receive number of incoming ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(&recv_size, 1, MPI_UNSIGNED_LONG, recv_proc, 300, MPI_COMM_WORLD, &requests[0]); // receive number of incoming ghosts + MPI_Isend(&send_size, 1, MPI_UNSIGNED_LONG, send_proc, 300, MPI_COMM_WORLD, &requests[1]); // send number of ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); + char* send_buffer = new char[send_size]; char* recv_buffer = new char[recv_size]; - send_size = this->to_buffer_save(send_buffer, send_min, send_max); // Large data transfer requires non-blocking communication - requests[0] = MPI::COMM_WORLD.Isend(send_buffer, send_size, MPI_CHAR, send_proc, 400); // send ghosts - requests[1] = MPI::COMM_WORLD.Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 400); // receive ghosts - MPI::Request::Waitall(2, requests); - MPI::COMM_WORLD.Barrier(); + MPI_Irecv(recv_buffer, recv_size, MPI_CHAR, recv_proc, 400, MPI_COMM_WORLD, &requests[0]); // receive ghosts + MPI_Isend(send_buffer, send_size, MPI_CHAR, send_proc, 400, MPI_COMM_WORLD, &requests[1]); // send ghosts + MPI_Waitall(2, requests, statuses); + MPI_Barrier(MPI_COMM_WORLD); this->from_buffer_save(recv_buffer, recv_min, recv_max); // populate ghost cell data from buffer @@ -1039,7 +1049,7 @@ template void grid::ghostswap(const int sublattice) recv_buffer=NULL; } } - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif } @@ -1181,10 +1191,14 @@ template void grid::input(const char* filename, int } // grid data type error check - std::string type; + std::string type, scalar_type; getline(input, type, '\n'); + scalar_type = "grid:scalar" + type.substr(type.find_last_of(":", 8)); + if (type != name(*this) && scalar_type == name(*this)) { + type = scalar_type; + } if (type != name(*this)) { - std::cerr << "File read error: wrong data type (" << type << ")." << std::endl; + std::cerr << "File read error: wrong data type (" << type << "), expected (" << name(*this) << ")." << std::endl; exit(-2); } @@ -1337,14 +1351,14 @@ template void grid::read(std::ifstream& file, int GH } #ifdef MPI_VERSION - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif } template void grid::output(const char* filename) const { #ifndef MPI_VERSION - unsigned int np=1; + int np=1; // file open error check std::ofstream output(filename); if (!output) { @@ -1395,10 +1409,11 @@ template void grid::output(const char* filename) con // C-style strings are null-terminated ('\0') by definition for (unsigned int i=0; i void grid::output(const char* filename) con std::cerr << "File output error: could not open " << fname << "." << std::endl; exit(-1); } - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); // Generate MMSP header from rank 0 unsigned long header_offset=0; @@ -1458,8 +1473,8 @@ template void grid::output(const char* filename) con header=NULL; } MPI_File_sync(output); - MPI::COMM_WORLD.Barrier(); - MPI::COMM_WORLD.Bcast(&header_offset, 1, MPI_UNSIGNED_LONG, 0); // broadcast header size from rank 0 + MPI_Barrier(MPI_COMM_WORLD); + MPI_Bcast(&header_offset, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); // broadcast header size from rank 0 // get grid data to write char* buffer=NULL; @@ -1468,16 +1483,16 @@ template void grid::output(const char* filename) con // Compute file offsets based on buffer sizes unsigned long* datasizes = new unsigned long[np]; - MPI::COMM_WORLD.Allgather(&size_of_buffer, 1, MPI_UNSIGNED_LONG, datasizes, 1, MPI_UNSIGNED_LONG); + MPI_Allgather(&size_of_buffer, 1, MPI_UNSIGNED_LONG, datasizes, 1, MPI_UNSIGNED_LONG, MPI_COMM_WORLD); // Calculate disk space unsigned long filesize=0; - for (unsigned int i=0; i(std::numeric_limits::max())); offsets[n]=offsets[n-1]+datasizes[n-1]; } @@ -1487,14 +1502,16 @@ template void grid::output(const char* filename) con #endif // Write buffer to disk - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); MPI_File_write_at_all(output, offsets[rank], buffer, datasizes[rank], MPI_CHAR, &status); #ifdef GRIDDEBUG - int error, write_errors=0; + int error, errclass, write_errors=0; MPI_Get_count(&status, MPI_INT, &error); - if (error!=0) - std::cerr<<" Error on Rank "< void grid::output(const char* filename) con // Make sure everything's written before closing the file. MPI_File_sync(output); - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); MPI_Offset actual_size; MPI_File_get_size(output, &actual_size); - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); MPI_File_close(&output); if (rank==0) { @@ -1537,7 +1554,7 @@ template void grid::output(const char* filename) con char* databuffer=NULL; char* headbuffer=NULL; char* filebuffer=NULL; - unsigned int* writeranks=NULL; + int* writeranks=NULL; MPI_Request* recvrequests = NULL; MPI_Status* recvstatuses = NULL; int mpi_err = 0; @@ -1568,27 +1585,27 @@ template void grid::output(const char* filename) con memcpy(headbuffer+header_offset, reinterpret_cast(&np), sizeof(np)); header_offset+=sizeof(rank); } - MPI::COMM_WORLD.Bcast(&header_offset, 1, MPI_UNSIGNED_LONG, 0); // broadcast header size from rank 0 + MPI_Bcast(&header_offset, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); // broadcast header size from rank 0 #ifdef GRIDDEBUG if (rank==0) std::cout<<"Prepared file header."<(std::numeric_limits::max())); offsets[n]=offsets[n-1]+datasizes[n-1]; } @@ -1599,9 +1616,9 @@ template void grid::output(const char* filename) con #endif // Calculate number of writers & write size - unsigned long blocks = filesize/blocksize; + unsigned int blocks = filesize/blocksize; while (blocks*blocksizenp)?np:blocks; + const unsigned int nwriters = (int(blocks)>np)?np:blocks; const unsigned long writesize=blocksize*(blocks/nwriters); assert(writesize % blocksize==0); const unsigned long excessblocks=blocks % nwriters; @@ -1611,10 +1628,10 @@ template void grid::output(const char* filename) con #endif // Scan to determine which ranks are writers - writeranks = new unsigned int[nwriters+1]; + writeranks = new int[nwriters+1]; aoffsets = new unsigned long[nwriters]; writeranks[nwriters]=np-1; // generalization for last writer's benefit - unsigned int temprank=0; + int temprank=0; for (unsigned int w=0; w void grid::output(const char* filename) con } // Collect block misalignments misalignments = new unsigned long[np]; - MPI::COMM_WORLD.Allgather(&deficiency, 1, MPI_UNSIGNED_LONG, misalignments, 1, MPI_UNSIGNED_LONG); + MPI_Allgather(&deficiency, 1, MPI_UNSIGNED_LONG, misalignments, 1, MPI_UNSIGNED_LONG, MPI_COMM_WORLD); #ifdef GRIDDEBUG if (datasizes[rank]-deficiency>ws) @@ -1665,9 +1682,9 @@ template void grid::output(const char* filename) con #endif // Accumulate data - const unsigned int silentranks=writeranks[nextwriter]-rank; // number of MPI ranks between this rank and the next writer + const int silentranks=writeranks[nextwriter]-rank; // number of MPI ranks between this rank and the next writer MPI_Request sendrequest; - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); if (isWriter) { // This rank is a writer. assert(misalignments[rank] < datasizes[rank]); @@ -1696,8 +1713,8 @@ template void grid::output(const char* filename) con recvrequests = new MPI_Request[silentranks]; recvstatuses = new MPI_Status[silentranks]; } - for (unsigned int i=0; inp) @@ -1709,7 +1726,7 @@ template void grid::output(const char* filename) con if (p+recv_size>filebuffer+ws) std::fprintf(stderr, "Error on Rank %u, receiving from %i: %lu B > %lu B\n", rank, recv_proc, p-filebuffer, ws-recv_size); #endif - MPI_Irecv(p, recv_size, MPI_CHAR, recv_proc, recv_proc, MPI::COMM_WORLD, &recvrequests[i]); + MPI_Irecv(p, recv_size, MPI_CHAR, recv_proc, recv_proc, MPI_COMM_WORLD, &recvrequests[i]); p+=recv_size; } #ifdef GRIDDEBUG @@ -1719,17 +1736,17 @@ template void grid::output(const char* filename) con if (rank>0 && misalignments[rank]>0) { q=databuffer; assert(writeranks[prevwriter]= datasizes[rank]) { assert(writeranks[prevwriter]0) MPI_Wait(&sendrequest, &status); - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); // file open error check #ifdef GRIDDEBUG @@ -1747,7 +1764,7 @@ template void grid::output(const char* filename) con std::cerr << "File output error: could not open " << fname << "." << std::endl; exit(-1); } - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); // Write to disk if (filebuffer!=NULL) { @@ -1757,7 +1774,7 @@ template void grid::output(const char* filename) con if (w==nwriters-1) assert(filesize-aoffsets[w]==ws); mpi_err = MPI_File_iwrite_at(output, aoffsets[w], filebuffer, ws, MPI_CHAR, &request); - MPI_Wait(&request, &status); + MPIO_Wait(&request, &status); if (mpi_err != MPI_SUCCESS) { char error_string[256]; int length_of_error_string=256; @@ -1769,7 +1786,7 @@ template void grid::output(const char* filename) con } MPI_File_sync(output); - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); MPI_File_close(&output); if (recvrequests!=NULL) { @@ -2152,6 +2169,24 @@ template MMSP::vector gradient(const grid& GRID return gradient; } +template MMSP::vector gradient(const grid >& GRID, const vector& x, const int field) +{ + vector gradient(dim); + vector s = x; + + for (int i=0; i vector grad(const grid& GRID, const vector& x) { return gradient(GRID, x); diff --git a/include/MMSP.grid.h b/include/MMSP.grid.h index beb3279..bb6c337 100644 --- a/include/MMSP.grid.h +++ b/include/MMSP.grid.h @@ -285,6 +285,10 @@ class grid { return GRID.g1[i]; } + friend int glength(const grid& GRID, int i) + { + return GRID.g1[i] - GRID.g0[i]; + } friend int b0(const grid& GRID, int i) { return GRID.b0[i]; @@ -411,7 +415,6 @@ class grid { return GRID.dx[1]; } - // grid utility functions (z direction) friend int z0(const grid& GRID) { @@ -451,33 +454,35 @@ class grid protected: T* data; // local grid data - int nodes; // number of nodes (excluding ghosts) - int cells; // number of nodes (including ghosts) - int fields; // number of fields - int ghosts; // ghost cell depth + int nodes; // number of nodes (excluding ghosts) + int cells; // number of nodes (including ghosts) + int fields; // number of fields + int ghosts; // ghost cell depth - int g0[dim]; // global lower coordinate limit (excluding ghosts) - int g1[dim]; // global upper coordinate limit (excluding ghosts) + #define dMax 3 - int x0[dim]; // local lower coordinate limit (excluding ghosts) - int x1[dim]; // local upper coordinate limit (excluding ghosts) - int xx[dim]; // local cells in slice (excluding ghosts) + int g0[dMax]; // global lower coordinate limit (excluding ghosts) + int g1[dMax]; // global upper coordinate limit (excluding ghosts) - int s0[dim]; // local lower coordinate limit (including ghosts) - int s1[dim]; // local upper coordinate limit (including ghosts) - int sx[dim]; // local cells in slice (including ghosts) + int x0[dMax]; // local lower coordinate limit (excluding ghosts) + int x1[dMax]; // local upper coordinate limit (excluding ghosts) + int xx[dMax]; // local cells in slice (excluding ghosts) - int b0[dim]; // boundary condition at x0 - int b1[dim]; // boundary condition at x1 + int s0[dMax]; // local lower coordinate limit (including ghosts) + int s1[dMax]; // local upper coordinate limit (including ghosts) + int sx[dMax]; // local cells in slice (including ghosts) - double dx[dim]; // global cell spacing + int b0[dMax]; // boundary condition at x0 + int b1[dMax]; // boundary condition at x1 - int p0[dim]; - int p1[dim]; - int sp[dim]; // global processors in slice + double dx[dMax]; // global cell spacing - int n0[dim]; // neighbor processor at x0 - int n1[dim]; // neighbor processor at x1 + int p0[dMax]; + int p1[dMax]; + int sp[dMax]; // global processors in slice + + int n0[dMax]; // neighbor processor at x0 + int n1[dMax]; // neighbor processor at x1 }; @@ -501,6 +506,8 @@ template sparse laplacian(const grid >& template vector gradient(const grid& GRID, const vector& x); +template vector gradient(const grid >& GRID, const vector& x, const int field); + template vector grad(const grid& GRID, const vector& x); template T divergence(const grid& GRID, const vector& x); diff --git a/include/MMSP.hpp b/include/MMSP.hpp index 373f5d3..dba8adb 100644 --- a/include/MMSP.hpp +++ b/include/MMSP.hpp @@ -11,3 +11,5 @@ #include"MMSP.sparse.h" #include"MMSP.grid.h" + +#include"MMSP.output.h" diff --git a/include/MMSP.main.hpp b/include/MMSP.main.hpp index 9ec3d88..4a73e43 100644 --- a/include/MMSP.main.hpp +++ b/include/MMSP.main.hpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) { // _exactly once_, making this the proper place for it. int rank = 0; #ifdef MPI_VERSION - rank = MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif srand(time(NULL)+rank); diff --git a/include/MMSP.output.cpp b/include/MMSP.output.cpp new file mode 100644 index 0000000..2d55edf --- /dev/null +++ b/include/MMSP.output.cpp @@ -0,0 +1,920 @@ +// MMSP.output.cpp +// Convert MMSP grid data to XML VTK image data format +// Questions/comments to trevor.keller@gmail.com (Trevor Keller) + +#include +#include + +namespace MMSP { + +#ifdef PNG_LIBPNG_VER +int writePNG(const int w, const int h, const int bpp, unsigned char* imData, const char* filename) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write PNG in parallel." < +void scalar_field_to_png(const grid& GRID, + const int& mode, int sliceaxis, int slicelevel, + const double& zoomin, const double& zoomax, + const bool coninv, const std::set& levelset, const int& lvlfield, + const double& contol, const unsigned int& bufsize, unsigned char* buffer) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write PNG in parallel." <max) + max=val; + else if (val x(1,0); + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + double val = GRID(x); + if (mode==1) //mag + val = std::fabs(val); + assert(n::iterator it=levelset.begin(); it!=levelset.end(); it++) + if (std::fabs(val-*it)/std::fabs(*it) x(2,0); + for (x[1] = g1(GRID,1)-1; x[1] >= g0(GRID,1); x[1]--) + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + double val = GRID(x); + if (mode==1) //mag + val = std::fabs(val); + assert(n::iterator it=levelset.begin(); it!=levelset.end(); it++) + if (std::fabs(val-*it)/std::fabs(*it) x(3,0); + for (x[2] = g0(GRID,2); x[2] < g1(GRID,2); x[2]++) + for (x[1] = g1(GRID,1)-1; x[1] >= g0(GRID,1); x[1]--) + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + if (x[sliceaxis]!=slicelevel) // clumsy, but effective + continue; + double val = GRID(x); + if (mode==1) //mag + val = std::fabs(val); + assert(n0) //contour + for (std::set::iterator it=levelset.begin(); it!=levelset.end(); it++) + if (std::fabs(val-*it)/std::fabs(*it) +void vector_field_to_png(const grid >& GRID, + const int& mode, int sliceaxis, int slicelevel, + const double& zoomin, const double& zoomax, + const bool coninv, const std::set& levelset, const int& lvlfield, + const double& contol, const std::set& fieldset, + const unsigned int& bufsize, unsigned char* buffer) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write PNG in parallel." <1) + sum += pow(GRID(n)[i],2.0); + else + sum = GRID(n)[i]; + } else if (mode==1) { // --mag + for (int i=0; i1) + for (std::set::iterator it=fieldset.begin(); it!=fieldset.end(); it++) + sum += pow(GRID(n)[*it],2.0); + else + sum = GRID(n)[*fieldset.begin()]; + } else if (mode==3) { // --exclude + for (int i=0; i::iterator it=fieldset.find(i); + if (it == fieldset.end()) { + if (included>1) + sum += pow(GRID(n)[i],2.0); + else + sum = GRID(n)[i]; + } + } + } + if (mode==1 || included!=1) + sum = std::sqrt(sum); + if (sum>max) + max=sum; + else if (sum x(1,0); + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + double sum=0.0; + if (mode==0) { // default selection + for (int i=0; i1) + sum += pow(GRID(x)[i],2.0); + else + sum = GRID(x)[i]; + } + } else if (mode==1) { // --mag + for (int i=0; i::iterator it=fieldset.begin(); it!=fieldset.end(); it++) + sum += pow(GRID(x)[*it],2.0); + } else if (mode==3) { // --exclude + for (int i=0; i::iterator it=fieldset.find(i); + if (it == fieldset.end()) { + if (included>1) + sum += pow(GRID(x)[i],2.0); + else + sum = GRID(x)[i]; + } + } + } + if (mode==1 || included!=1) + sum = std::sqrt(sum); + assert(n0) // --contour + for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) + if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(2,0); + for (x[1] = g1(GRID,1)-1; x[1] >= g0(GRID,1); x[1]--) + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + double sum=0.0; + if (mode==0) { // default selection + for (int i=0; i1) + sum += pow(GRID(x)[i],2.0); + else + sum = GRID(x)[i]; + } + } else if (mode==1) { // --mag + for (int i=0; i::iterator it=fieldset.begin(); it!=fieldset.end(); it++) + sum += pow(GRID(x)[*it],2.0); + } + } else if (mode==3) { // --exclude + for (int i=0; i::iterator it=fieldset.find(i); + if (it == fieldset.end()) { + if (included>1) + sum += pow(GRID(x)[i],2.0); + else + sum = GRID(x)[i]; + } + } + } + if (mode==1 || included!=1) + sum = std::sqrt(sum); + assert(n0) // --contour + for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) + if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(3,0); + for (x[2] = g0(GRID,2); x[2] < g1(GRID,2); x[2]++) + for (x[1] = g1(GRID,1)-1; x[1] >= g0(GRID,1); x[1]--) + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + if (x[sliceaxis]!=slicelevel) // clumsy, but effective + continue; + double sum=0.0; + if (mode==0) { // default selection + for (int i=0; i1) + sum += pow(GRID(x)[i],2.0); + else + sum = GRID(x)[i]; + } + } else if (mode==1) { // --mag + for (int i=0; i::iterator it=fieldset.begin(); it!=fieldset.end(); it++) + sum += pow(GRID(x)[*it],2.0); + } else if (mode==3) { // --exclude + for (int i=0; i::iterator it=fieldset.find(i); + if (it == fieldset.end()) { + if (included>1) + sum += pow(GRID(x)[i],2.0); + else + sum = GRID(x)[i]; + } + } + } + if (mode==1 || included!=1) + sum = std::sqrt(sum); + assert(n0) // --contour + for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) + if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) +void sparse_field_to_png(const grid >& GRID, + const int& mode, int sliceaxis, int slicelevel, + const double& zoomin, const double& zoomax, + const bool coninv, const std::set& levelset, const int& lvlfield, + const double& contol, const std::set& fieldset, + const unsigned int& bufsize, unsigned char* buffer) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write PNG in parallel." <::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { + if (included>1) + sum += pow(GRID(n)[*it],2.0); + else + sum = GRID(n)[*it]; + } + } else if (mode==3) { // --exclude + for (int h=0; h::iterator it=fieldset.find(i); + if (it == fieldset.end()) + sum += pow(GRID(n).value(h),2.0); + } + } + if (included!=1) + sum = std::sqrt(sum); + if (sum>max) + max=sum; + else if (sum x(1,0); + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + double sum=0.0; + if (mode<2) { // --mag + for (int h=0; h::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { + if (included>1) + sum += pow(GRID(x)[*it],2.0); + else + sum = GRID(x)[*it]; + } + } else if (mode==3) { // --exclude + for (int h=0; h::iterator it=fieldset.find(i); + if (it == fieldset.end()) + sum += pow(GRID(x).value(h),2.0); + } + } + if (mode!=2 || included!=1) + sum = std::sqrt(sum); + assert(n0) // --contour + for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) + if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(2,0); + for (x[1] = g1(GRID,1)-1; x[1] >= g0(GRID,1); x[1]--) + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + double sum=0.0; + if (mode<2) { // --mag + for (int h=0; h::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { + if (included>1) + sum += pow(GRID(x)[*it],2.0); + else + sum = GRID(x)[*it]; + } + } else if (mode==3) { // --exclude + for (int h=0; h::iterator it=fieldset.find(i); + if (it == fieldset.end()) + sum += pow(GRID(x).value(h),2.0); + } + } + if (mode!=2 || included!=1) + sum = std::sqrt(sum); + assert(n0) // --contour + for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) + if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(3,0); + for (x[2] = g0(GRID,2); x[2] < g1(GRID,2); x[2]++) + for (x[1] = g1(GRID,1)-1; x[1] >= g0(GRID,1); x[1]--) + for (x[0] = g0(GRID,0); x[0] < g1(GRID,0); x[0]++) { + if (x[sliceaxis]!=slicelevel) // clumsy, but effective + continue; + double sum=0.0; + if (mode<2) { // --mag + for (int h=0; h::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { + if (included>1) + sum += pow(GRID(x)[*it],2.0); + else + sum = GRID(x)[*it]; + } + } else if (mode==3) { // --exclude + for (int h=0; h::iterator it=fieldset.find(i); + if (it == fieldset.end()) + sum += pow(GRID(x).value(h),2.0); + } + } + if (mode!=2 || included!=1) + sum = std::sqrt(sum); + assert(n0) // --contour + for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) + if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) +void scalar_field_to_vtk(std::string filename, const grid& GRID, const int mode) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write VTK in parallel." < scalarData = vtkSmartPointer::New(); + + if (dim==1) { + scalarData->SetDimensions(x1(GRID)-x0(GRID), 1, 1); + scalarData->SetExtent(x0(GRID), x1(GRID) - 1, 0, 0, 0, 0); + scalarData->SetSpacing(dx(GRID), 1, 1); + #if VTK_MAJOR_VERSION <= 5 + scalarData->SetScalarTypeToFloat(); + scalarData->SetNumberOfScalarComponents(1); + #else + scalarData->AllocateScalars(VTK_FLOAT, 1); + #endif + + vector x(1,0); + for (x[0]=x0(GRID); x[0](scalarData->GetScalarPointer(x[0], 0, 0)); + if (mode==1) { // --mag + *pixel = std::sqrt(GRID(x)*GRID(x)); + } else { + *pixel = GRID(x); + } + } + } else if (dim==2) { + scalarData->SetDimensions(x1(GRID)-x0(GRID), + y1(GRID)-y0(GRID), + 1); + scalarData->SetExtent(x0(GRID), x1(GRID) - 1, + y0(GRID), y1(GRID) - 1, + 0, 0); + scalarData->SetSpacing(dx(GRID, 0), dx(GRID, 1), 1); + #if VTK_MAJOR_VERSION <= 5 + scalarData->SetScalarTypeToFloat(); + scalarData->SetNumberOfScalarComponents(1); + #else + scalarData->AllocateScalars(VTK_FLOAT, 1); + #endif + + vector x(2,0); + for (x[1]=y0(GRID); x[1](scalarData->GetScalarPointer(x[0], x[1], 0)); + if (mode==1) { // --mag + *pixel = std::sqrt(GRID(x)*GRID(x)); + } else { + *pixel = GRID(x); + } + } + } + } else if (dim==3) { + scalarData->SetDimensions(x1(GRID)-x0(GRID), + y1(GRID)-y0(GRID), + z1(GRID)-z0(GRID)); + scalarData->SetExtent(x0(GRID), x1(GRID) - 1, + y0(GRID), y1(GRID) - 1, + z0(GRID), z1(GRID) - 1); + scalarData->SetSpacing(dx(GRID, 0), dx(GRID, 1), dx(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + scalarData->SetScalarTypeToFloat(); + scalarData->SetNumberOfScalarComponents(1); + #else + scalarData->AllocateScalars(VTK_FLOAT, 1); + #endif + + vector x(3,0); + for (x[2]=z0(GRID); x[2](scalarData->GetScalarPointer(x[0], x[1], x[2])); + if (mode==1) { // --mag + *pixel = std::sqrt(GRID(x)*GRID(x)); + } else { + *pixel = GRID(x); + } + } + } + } + } + scalarData->GetPointData()->GetAbstractArray(0)->SetName("scalar_data"); + + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(filename.c_str()); + #if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(scalarData->GetProducerPort()); + #else + writer->SetInputData(scalarData); + #endif + writer->SetDataModeToBinary(); + writer->SetCompressorTypeToZLib(); + writer->Write(); + + scalarData = NULL; + writer = NULL; +} + +template +void vector_field_to_vtk(std::string filename, const grid >& GRID, + const int mode, const int field) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write VTK in parallel." < vectorData = vtkSmartPointer::New(); + + if (dim==1) { + vectorData->SetDimensions(x1(GRID)-x0(GRID), 1, 1); + vectorData->SetExtent(x0(GRID), x1(GRID) - 1, 0, 0, 0, 0); + vectorData->SetSpacing(dx(GRID), 1, 1); + #if VTK_MAJOR_VERSION <= 5 + vectorData->SetScalarTypeToFloat(); + if (mode==1 || mode==2 || mode==3) + vectorData->SetNumberOfScalarComponents(1); + else + vectorData->SetNumberOfScalarComponents(fields(GRID)); + #else + if (mode==1 || mode==2 || mode==3) + vectorData->AllocateScalars(VTK_FLOAT, 1); + else + vectorData->AllocateScalars(VTK_FLOAT, fields(GRID)); + #endif + + vector x(1,0); + for (x[0]=x0(GRID); x[0]& v = GRID(x); + float* pixel = static_cast(vectorData->GetScalarPointer(x[0], 0, 0)); + if (mode==1) { // --mag + double sum = 0.0; + for (int h = 0; h < v.length(); h++) + sum += v[h]*v[h]; + *pixel = std::sqrt(sum); + } else if (mode==2) { // --max + // Export index of field with greatest magnitude + int max = 0; + for (int h = 1; h < v.length(); h++) + if (v[h] > v[max]) + max = h; + *pixel = max; + } else if (mode==3) { // --field + *pixel = v[field]; + } else { + for (int h = 0; h < v.length(); h++) + pixel[h] = v[h]; + } + } + } else if (dim==2) { + vectorData->SetDimensions(x1(GRID)-x0(GRID), + y1(GRID)-y0(GRID), + 1); + vectorData->SetExtent(x0(GRID), x1(GRID) - 1, + y0(GRID), y1(GRID) - 1, + 0, 0); + vectorData->SetSpacing(dx(GRID, 0), dx(GRID, 1), 1); + #if VTK_MAJOR_VERSION <= 5 + vectorData->SetScalarTypeToFloat(); + if (mode==1 || mode==2 || mode==3) + vectorData->SetNumberOfScalarComponents(1); + else + vectorData->SetNumberOfScalarComponents(fields(GRID)); + #else + if (mode==1 || mode==2 || mode==3) + vectorData->AllocateScalars(VTK_DOUBLE, 1); + else + vectorData->AllocateScalars(VTK_DOUBLE, fields(GRID)); + #endif + + vector x(2,0); + for (x[1]=y0(GRID); x[1]& v = GRID(x); + double* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], 0)); + if (mode==1) { // --mag + double sum = 0.0; + for (int h = 0; h < v.length(); h++) + sum += v[h]*v[h]; + *pixel = std::sqrt(sum); + } else if (mode==2) { // --max + // Export index of field with greatest magnitude + int max = 0; + for (int h = 1; h < v.length(); h++) + if (v[h] > v[max]) + max = h; + *pixel = max; + } else if (mode==3) { // --field + *pixel = v[field]; + } else { + for (int h = 0; h < v.length(); h++) + pixel[h] = v[h]; + } + } + } + } else if (dim==3) { + vectorData->SetDimensions(x1(GRID)-x0(GRID), + y1(GRID)-y0(GRID), + z1(GRID)-z0(GRID)); + vectorData->SetExtent(x0(GRID), x1(GRID) - 1, + y0(GRID), y1(GRID) - 1, + z0(GRID), z1(GRID) - 1); + vectorData->SetSpacing(dx(GRID, 0), dx(GRID, 1), dx(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + vectorData->SetScalarTypeToFloat(); + if (mode==1 || mode==2 || mode==3) + vectorData->SetNumberOfScalarComponents(1); + else + vectorData->SetNumberOfScalarComponents(fields(GRID)); + #else + if (mode==1 || mode==2 || mode==3) + vectorData->AllocateScalars(VTK_FLOAT, 1); + else + vectorData->AllocateScalars(VTK_FLOAT, fields(GRID)); + #endif + + vector x(3,0); + for (x[2]=z0(GRID); x[2]& v = GRID(x); + float* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], x[2])); + if (mode==1) { // --mag + double sum = 0.0; + for (int h = 0; h < v.length(); h++) + sum += v[h]*v[h]; + *pixel = std::sqrt(sum); + } else if (mode==2) { // --max + // Export index of field with greatest magnitude + int max = 0; + for (int h = 1; h < v.length(); h++) + if (v[h] > v[max]) + max = h; + *pixel = max; + } else if (mode==3) { // --field + *pixel = v[field]; + } else { + for (int h = 0; h < v.length(); h++) + pixel[h] = v[h]; + } + } + } + } + } + + // vectorData->GetPointData()->GetAbstractArray(0)->SetName("vector_data"); + + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(filename.c_str()); + #if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(vectorData->GetProducerPort()); + #else + writer->SetInputData(vectorData); + #endif + writer->SetDataModeToBinary(); + writer->SetCompressorTypeToZLib(); + writer->Write(); + + vectorData = NULL; + writer = NULL; +} + +template +void sparse_field_to_vtk(std::string filename, const grid >& GRID, + const int mode, const int field) +{ + #ifdef MPI_VERSION + std::cerr << "Error: cannot write VTK in parallel." < sparseData = vtkSmartPointer::New(); + + if (dim==1) { + sparseData->SetDimensions(x1(GRID)-x0(GRID), 1, 1); + sparseData->SetExtent(x0(GRID), x1(GRID) - 1, 0, 0, 0, 0); + sparseData->SetSpacing(dx(GRID, 0), 1, 1); + #if VTK_MAJOR_VERSION <= 5 + sparseData->SetNumberOfScalarComponents(1); + sparseData->SetScalarTypeToFloat(); + #else + sparseData->AllocateScalars(VTK_FLOAT, 1); + #endif + + vector x(1,0); + for (x[0]=x0(GRID); x[0]& s = GRID(x); + float* pixel = static_cast(sparseData->GetScalarPointer(x[0], 0, 0)); + if (mode==2) { // --max + // Export index of field with greatest magnitude + int max = 0; + for (int h = 1; h < s.length(); h++) + if (s.value(h) > s.value(max)) + max = h; + *pixel = s.index(max); + } else if (mode==3) { // --field + *pixel = s[field]; + } else { // --mag is redundant for sparse + double sum = 0.0; + for (int h = 0; h < s.length(); h++) + sum += s.value(h)*s.value(h); + *pixel = std::sqrt(sum); + } + } + } else if (dim==2) { + sparseData->SetDimensions(x1(GRID)-x0(GRID), + y1(GRID)-y0(GRID), + 1); + sparseData->SetExtent(x0(GRID), x1(GRID) - 1, + y0(GRID), y1(GRID) - 1, + 0, 0); + sparseData->SetSpacing(dx(GRID, 0), dx(GRID, 1), 1); + #if VTK_MAJOR_VERSION <= 5 + sparseData->SetNumberOfScalarComponents(1); + sparseData->SetScalarTypeToFloat(); + #else + sparseData->AllocateScalars(VTK_FLOAT, 1); + #endif + + vector x(2,0); + for (x[1]=y0(GRID); x[1]& s = GRID(x); + float* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], 0)); + if (mode==2) { // --max + // Export index of field with greatest magnitude + int max = 0; + for (int h = 1; h < s.length(); h++) + if (s.value(h) > s.value(max)) + max = h; + *pixel = s.index(max); + } else if (mode==3) { // --field + *pixel = s[field]; + } else { // --mag is redundant for sparse + double sum = 0.0; + for (int h = 0; h < s.length(); h++) + sum += s.value(h)*s.value(h); + *pixel = std::sqrt(sum); + } + } + } + } else if (dim==3) { + sparseData->SetDimensions(x1(GRID)-x0(GRID), + y1(GRID)-y0(GRID), + z1(GRID)-z0(GRID)); + sparseData->SetExtent(x0(GRID), x1(GRID) - 1, + y0(GRID), y1(GRID) - 1, + z0(GRID), z1(GRID) - 1); + sparseData->SetSpacing(dx(GRID, 0), dx(GRID, 1), dx(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + sparseData->SetNumberOfScalarComponents(1); + sparseData->SetScalarTypeToFloat(); + #else + sparseData->AllocateScalars(VTK_FLOAT, 1); + #endif + + vector x(3,0); + for (x[2]=z0(GRID); x[2]& s = GRID(x); + float* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], x[2])); + if (mode==2) { // --max + // Export index of field with greatest magnitude + int max = 0; + for (int h = 1; h < s.length(); h++) + if (s.value(h) > s.value(max)) + max = h; + *pixel = s.index(max); + } else if (mode==3) { // --field + *pixel = s[field]; + } else { // --mag is redundant for sparse + double sum = 0.0; + for (int h = 0; h < s.length(); h++) + sum += s.value(h)*s.value(h); + *pixel = std::sqrt(sum); + } + } + } + } + } + sparseData->GetPointData()->GetAbstractArray(0)->SetName("sparse_data"); + + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(filename.c_str()); + #if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(sparseData->GetProducerPort()); + #else + writer->SetInputData(sparseData); + #endif + writer->SetDataModeToBinary(); + writer->SetCompressorTypeToZLib(); + writer->Write(); + + sparseData = NULL; + writer = NULL; +} +#endif // VTK + +} // namespace diff --git a/include/MMSP.output.h b/include/MMSP.output.h new file mode 100644 index 0000000..4ec90be --- /dev/null +++ b/include/MMSP.output.h @@ -0,0 +1,51 @@ +// MMSP.output.hpp +// Declaration of MMSP output functions +// Questions/comments to trevor.keller@gmail.com (Trevor Keller) + +#include +#include + +namespace MMSP { + #ifdef PNG_LIBPNG_VER + int writePNG(const int w, const int h, const int bpp, unsigned char* imData, const char* filename); + + template + void scalar_field_to_png(const grid& GRID, + const int& mode, int sliceaxis, int slicelevel, + const double& zoomin, const double& zoomax, + const bool coninv, const std::set& levelset, const int& lvlfield, + const double& contol, const unsigned int& bufsize, unsigned char* buffer); + + template + void vector_field_to_png(const grid >& GRID, + const int& mode, int sliceaxis, int slicelevel, + const double& zoomin, const double& zoomax, + const bool coninv, const std::set& levelset, const int& lvlfield, + const double& contol, const std::set& fieldset, + const unsigned int& bufsize, unsigned char* buffer); + + template + void sparse_field_to_png(const grid >& GRID, + const int& mode, int sliceaxis, int slicelevel, + const double& zoomin, const double& zoomax, + const bool coninv, const std::set& leveOBlset, const int& lvlfield, + const double& contol, const std::set& fieldset, + const unsigned int& bufsize, unsigned char* buffer); + #endif // PNG + + #ifdef VTK_VERSION + template + void scalar_field_to_vtk(std::string filename, const grid& GRID, const int mode); + + template + void vector_field_to_vtk(std::string filename, const grid >& GRID, + const int mode, const int field); + + template + void sparse_field_to_vtk(std::string filename, const grid >& GRID, + const int mode, const int field); + #endif // VTK + +} // namespace + +#include "MMSP.output.cpp" diff --git a/include/MMSP.utility.cpp b/include/MMSP.utility.cpp index 2cb51a1..ad9bb2e 100644 --- a/include/MMSP.utility.cpp +++ b/include/MMSP.utility.cpp @@ -14,7 +14,7 @@ namespace MMSP void Init(int argc, char* argv[]) { #ifdef MPI_VERSION - MPI::Init(argc, argv); + MPI_Init(&argc, &argv); #endif } @@ -22,7 +22,7 @@ void Init(int argc, char* argv[]) void Finalize() { #ifdef MPI_VERSION - MPI::Finalize(); + MPI_Finalize(); #endif } @@ -30,7 +30,7 @@ void Finalize() void Abort(int err) { #ifdef MPI_VERSION - MPI::COMM_WORLD.Abort(err); + MPI_Abort(MPI_COMM_WORLD, err); #endif exit(err); } @@ -64,17 +64,19 @@ template T global(T& value, const char* operation) T global = value; #ifdef MPI_VERSION - int rank = MPI::COMM_WORLD.Get_rank(); - int np = MPI::COMM_WORLD.Get_size(); + int rank = 0, np = 1; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &np); + MPI_Status status; if (rank == 0) { // receive local values for (int i = 1; i < np; i++) { T temp; int size; - MPI::COMM_WORLD.Recv(&size, 1, MPI_INT, i, 100); + MPI_Recv(&size, 1, MPI_INT, i, 100, MPI_COMM_WORLD, &status); char* buffer = new char[size]; - MPI::COMM_WORLD.Recv(buffer, size, MPI_CHAR, i, 200); + MPI_Recv(buffer, size, MPI_CHAR, i, 200, MPI_COMM_WORLD, &status); from_buffer(temp, buffer); if (buffer != NULL) { delete [] buffer; @@ -93,10 +95,10 @@ template T global(T& value, const char* operation) // send global value for (int i = 1; i < np; i++) { int size = buffer_size(global); - MPI::COMM_WORLD.Send(&size, 1, MPI_INT, i, 300); + MPI_Send(&size, 1, MPI_INT, i, 300, MPI_COMM_WORLD); char* buffer = new char[size]; to_buffer(global, buffer); - MPI::COMM_WORLD.Send(buffer, size, MPI_CHAR, i, 400); + MPI_Send(buffer, size, MPI_CHAR, i, 400, MPI_COMM_WORLD); if (buffer != NULL) { delete [] buffer; buffer=NULL; @@ -107,19 +109,19 @@ template T global(T& value, const char* operation) else { // send local value int size = buffer_size(value); - MPI::COMM_WORLD.Send(&size, 1, MPI_INT, 0, 100); + MPI_Send(&size, 1, MPI_INT, 0, 100, MPI_COMM_WORLD); char* buffer = new char[size]; to_buffer(value, buffer); - MPI::COMM_WORLD.Send(buffer, size, MPI_CHAR, 0, 200); + MPI_Send(buffer, size, MPI_CHAR, 0, 200, MPI_COMM_WORLD); if (buffer != NULL) { delete [] buffer; buffer=NULL; } // receive global value - MPI::COMM_WORLD.Recv(&size, 1, MPI_INT, 0, 300); + MPI_Recv(&size, 1, MPI_INT, 0, 300, MPI_COMM_WORLD, &status); buffer = new char[size]; - MPI::COMM_WORLD.Recv(buffer, size, MPI_CHAR, 0, 400); + MPI_Recv(buffer, size, MPI_CHAR, 0, 400, MPI_COMM_WORLD, &status); from_buffer(global, buffer); if (buffer != NULL) { delete [] buffer; @@ -127,7 +129,7 @@ template T global(T& value, const char* operation) } } - MPI::COMM_WORLD.Barrier(); + MPI_Barrier(MPI_COMM_WORLD); #endif return global; @@ -139,8 +141,13 @@ void print_progress(const int step, const int steps) Prints timestamps and a 20-point progress bar to stdout. Call once inside the update function (or equivalent). - for (int step=0; step T global(T& value, const char* operation); // simple progress bar for the terminal void print_progress(const int step, const int steps); - } // namespace MMSP #include "MMSP.utility.cpp" diff --git a/test/MMSP.exampleTestSuite.cpp b/test/MMSP.exampleTestSuite.cpp index 543275b..afe7c6a 100644 --- a/test/MMSP.exampleTestSuite.cpp +++ b/test/MMSP.exampleTestSuite.cpp @@ -34,13 +34,13 @@ int main(int argc, char* argv[]) { MMSP::Init(argc, argv); - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); int rank=0; #ifdef MPI_VERSION - rank=MPI::COMM_WORLD.Get_rank(); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif srand(time(NULL)+rank); - int result = RUN_ALL_TESTS(); - MMSP::Finalize(); - return result; + int result = RUN_ALL_TESTS(); + MMSP::Finalize(); + return result; } diff --git a/test/MMSP.unitTestSuite.hpp b/test/MMSP.unitTestSuite.hpp index 98d971d..2bb605e 100644 --- a/test/MMSP.unitTestSuite.hpp +++ b/test/MMSP.unitTestSuite.hpp @@ -117,7 +117,8 @@ TYPED_TEST(gridTest, testSize) { #ifndef MPI_VERSION EXPECT_EQ(MMSP::nodes(this->grid1D),64); #else - int np = MPI::COMM_WORLD.Get_size(); + int np = 0; + MPI_Comm_size(MPI_COMM_WORLD, &size); EXPECT_LE(MMSP::nodes(this->grid1D),1+64/np); #endif EXPECT_EQ(this->grid1D.buffer_size(),MMSP::nodes(this->grid1D)*sizeof(TypeParam)); diff --git a/test/test.cpp b/test/test.cpp index e6dafb4..5be566c 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -13,8 +13,9 @@ int main(int argc, char* argv[]) #endif #ifdef MPI_VERSION - int id = MPI::COMM_WORLD.Get_rank(); - int np = MPI::COMM_WORLD.Get_size(); + int id = 0, np = 1; + MPI_Comm_rank(MPI_COMM_WORLD, &id); + MPI_Comm_size(MPI_COMM_WORLD, &np); std::cout<<"This is a test (processor "< #include #include -#include +#include #include"MMSP.hpp" -int writePNG(const int w, const int h, const int bpp, unsigned char* imData, const char* filename); - -template void convert_scalars(const MMSP::grid& GRID, - const int& mode, int sliceaxis, int slicelevel, const double& zoomin, const double& zoomax, const bool coninv, - const std::set& levelset, const int& lvlfield, const double& contol, const unsigned int& bufsize, unsigned char* buffer); - -template void convert_vectors(const MMSP::grid >& GRID, - const int& mode, int sliceaxis, int slicelevel, const double& zoomin, const double& zoomax, const bool coninv, - const std::set& levelset, const int& lvlfield, const double& contol, const std::set& fieldset, - const unsigned int& bufsize, unsigned char* buffer); - -template void convert_sparses(const MMSP::grid >& GRID, - const int& mode, int sliceaxis, int slicelevel, const double& zoomin, const double& zoomax, const bool coninv, - const std::set& levelset, const int& lvlfield, const double& contol, const std::set& fieldset, - const unsigned int& bufsize, unsigned char* buffer); - int main(int argc, char* argv[]) { // command line error check @@ -329,145 +313,145 @@ int main(int argc, char* argv[]) if (bool_type) { if (dim == 1) { MMSP::grid<1,bool> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,bool> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,bool> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (unsigned_char_type) { if (dim == 1) { MMSP::grid<1,unsigned char> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,unsigned char> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,unsigned char> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (char_type) { if (dim == 1) { MMSP::grid<1,char> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,char> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,char> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (unsigned_int_type) { if (dim == 1) { MMSP::grid<1,unsigned int> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,unsigned int> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,unsigned int> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (int_type) { if (dim == 1) { MMSP::grid<1,int> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,int> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,int> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (unsigned_long_type) { if (dim == 1) { MMSP::grid<1,unsigned long> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,unsigned long> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,unsigned long> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (long_type) { if (dim == 1) { MMSP::grid<1,long> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,long> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,long> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (unsigned_short_type) { if (dim == 1) { MMSP::grid<1,unsigned short> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,unsigned short> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,unsigned short> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (short_type) { if (dim == 1) { MMSP::grid<1,short> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,short> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,short> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (float_type) { if (dim == 1) { MMSP::grid<1,float> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,float> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,float> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (long_double_type) { if (dim == 1) { MMSP::grid<1,long double> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,long double> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,long double> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } else if (double_type) { if (dim == 1) { MMSP::grid<1,double> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,double> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,double> GRID(argv[datindex]); - convert_scalars(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); + scalar_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, theSize, buffer); } } } @@ -475,145 +459,145 @@ int main(int argc, char* argv[]) if (bool_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_char_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (char_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_int_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (int_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_long_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (long_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_short_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (short_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (float_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (long_double_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (double_type) { if (dim == 1) { MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + vector_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } } @@ -622,145 +606,145 @@ int main(int argc, char* argv[]) if (bool_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_char_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (char_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_int_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (int_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_long_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (long_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (unsigned_short_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (short_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (float_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (long_double_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } else if (double_type) { if (dim == 1) { MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 2) { MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } else if (dim == 3) { MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); + sparse_field_to_png(GRID, mode, sliceaxis, slicelevel, zoomin, zoomax, coninv, levelset, lvlfield, contol, fieldset, theSize, buffer); } } } @@ -769,7 +753,7 @@ int main(int argc, char* argv[]) for (unsigned int n=0; n void convert_scalars(const MMSP::grid& GRID, - const int& mode, int sliceaxis, int slicelevel, const double& zoomin, const double& zoomax, const bool coninv, - const std::set& levelset, const int& lvlfield, const double& contol, const unsigned int& bufsize, unsigned char* buffer) -{ - double min=zoomin; - double max=zoomax; - - for (int n=0; nmax) - max=val; - else if (val x(1,0); - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - T val = GRID(x); - if (mode==1) //mag - val = std::abs(val); - assert(n::iterator it=levelset.begin(); it!=levelset.end(); it++) - if (std::fabs(val-*it)/std::fabs(*it) x(2,0); - for (x[1] = MMSP::g1(GRID,1)-1; x[1] >= MMSP::g0(GRID,1); x[1]--) - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - T val = GRID(x); - if (mode==1) //mag - val = std::abs(val); - assert(n::iterator it=levelset.begin(); it!=levelset.end(); it++) - if (std::fabs(val-*it)/std::fabs(*it) x(3,0); - for (x[2] = MMSP::g0(GRID,2); x[2] < MMSP::g1(GRID,2); x[2]++) - for (x[1] = MMSP::g1(GRID,1)-1; x[1] >= MMSP::g0(GRID,1); x[1]--) - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - if (x[sliceaxis]!=slicelevel) // clumsy, but effective - continue; - T val = GRID(x); - if (mode==1) //mag - val = std::abs(val); - assert(n0) //contour - for (std::set::iterator it=levelset.begin(); it!=levelset.end(); it++) - if (std::fabs(val-*it)/std::fabs(*it) void convert_vectors(const MMSP::grid >& GRID, - const int& mode, int sliceaxis, int slicelevel, const double& zoomin, const double& zoomax, const bool coninv, - const std::set& levelset, const int& lvlfield, const double& contol, const std::set& fieldset, - const unsigned int& bufsize, unsigned char* buffer) -{ - double min=zoomin; - double max=zoomax; - int included = (mode==2) ? fieldset.size() : MMSP::fields(GRID)-fieldset.size(); - - for (int n=0; n1) - sum += pow(GRID(n)[i],2.0); - else - sum = GRID(n)[i]; - } else if (mode==1) { // --mag - for (int i=0; i1) - for (std::set::iterator it=fieldset.begin(); it!=fieldset.end(); it++) - sum += pow(GRID(n)[*it],2.0); - else - sum = GRID(n)[*fieldset.begin()]; - } else if (mode==3) { // --exclude - for (int i=0; i::iterator it=fieldset.find(i); - if (it == fieldset.end()) { - if (included>1) - sum += pow(GRID(n)[i],2.0); - else - sum = GRID(n)[i]; - } - } - } - if (mode==1 || included!=1) - sum = std::sqrt(sum); - if (sum>max) - max=sum; - else if (sum x(1,0); - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - double sum=0.0; - if (mode==0) { // default selection - for (int i=0; i1) - sum += pow(GRID(x)[i],2.0); - else - sum = GRID(x)[i]; - } - } else if (mode==1) { // --mag - for (int i=0; i::iterator it=fieldset.begin(); it!=fieldset.end(); it++) - sum += pow(GRID(x)[*it],2.0); - } else if (mode==3) { // --exclude - for (int i=0; i::iterator it=fieldset.find(i); - if (it == fieldset.end()) { - if (included>1) - sum += pow(GRID(x)[i],2.0); - else - sum = GRID(x)[i]; - } - } - } - if (mode==1 || included!=1) - sum = std::sqrt(sum); - assert(n0) // --contour - for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) - if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(2,0); - for (x[1] = MMSP::g1(GRID,1)-1; x[1] >= MMSP::g0(GRID,1); x[1]--) - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - double sum=0.0; - if (mode==0) { // default selection - for (int i=0; i1) - sum += pow(GRID(x)[i],2.0); - else - sum = GRID(x)[i]; - } - } else if (mode==1) { // --mag - for (int i=0; i::iterator it=fieldset.begin(); it!=fieldset.end(); it++) - sum += pow(GRID(x)[*it],2.0); - } - } else if (mode==3) { // --exclude - for (int i=0; i::iterator it=fieldset.find(i); - if (it == fieldset.end()) { - if (included>1) - sum += pow(GRID(x)[i],2.0); - else - sum = GRID(x)[i]; - } - } - } - if (mode==1 || included!=1) - sum = std::sqrt(sum); - assert(n0) // --contour - for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) - if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(3,0); - for (x[2] = MMSP::g0(GRID,2); x[2] < MMSP::g1(GRID,2); x[2]++) - for (x[1] = MMSP::g1(GRID,1)-1; x[1] >= MMSP::g0(GRID,1); x[1]--) - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - if (x[sliceaxis]!=slicelevel) // clumsy, but effective - continue; - double sum=0.0; - if (mode==0) { // default selection - for (int i=0; i1) - sum += pow(GRID(x)[i],2.0); - else - sum = GRID(x)[i]; - } - } else if (mode==1) { // --mag - for (int i=0; i::iterator it=fieldset.begin(); it!=fieldset.end(); it++) - sum += pow(GRID(x)[*it],2.0); - } else if (mode==3) { // --exclude - for (int i=0; i::iterator it=fieldset.find(i); - if (it == fieldset.end()) { - if (included>1) - sum += pow(GRID(x)[i],2.0); - else - sum = GRID(x)[i]; - } - } - } - if (mode==1 || included!=1) - sum = std::sqrt(sum); - assert(n0) // --contour - for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) - if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) void convert_sparses(const MMSP::grid >& GRID, - const int& mode, int sliceaxis, int slicelevel, const double& zoomin, const double& zoomax, const bool coninv, - const std::set& levelset, const int& lvlfield, const double& contol, const std::set& fieldset, - const unsigned int& bufsize, unsigned char* buffer) -{ - double min=zoomin; - double max=zoomax; - int included = fieldset.size(); - - for (int n=0; n::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { - if (included>1) - sum += pow(GRID(n)[*it],2.0); - else - sum = GRID(n)[*it]; - } - } else if (mode==3) { // --exclude - for (int h=0; h::iterator it=fieldset.find(i); - if (it == fieldset.end()) - sum += pow(GRID(n).value(h),2.0); - } - } - if (included!=1) - sum = std::sqrt(sum); - if (sum>max) - max=sum; - else if (sum x(1,0); - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - double sum=0.0; - if (mode<2) { // --mag - for (int h=0; h::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { - if (included>1) - sum += pow(GRID(x)[*it],2.0); - else - sum = GRID(x)[*it]; - } - } else if (mode==3) { // --exclude - for (int h=0; h::iterator it=fieldset.find(i); - if (it == fieldset.end()) - sum += pow(GRID(x).value(h),2.0); - } - } - if (mode!=2 || included!=1) - sum = std::sqrt(sum); - assert(n0) // --contour - for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) - if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(2,0); - for (x[1] = MMSP::g1(GRID,1)-1; x[1] >= MMSP::g0(GRID,1); x[1]--) - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - double sum=0.0; - if (mode<2) { // --mag - for (int h=0; h::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { - if (included>1) - sum += pow(GRID(x)[*it],2.0); - else - sum = GRID(x)[*it]; - } - } else if (mode==3) { // --exclude - for (int h=0; h::iterator it=fieldset.find(i); - if (it == fieldset.end()) - sum += pow(GRID(x).value(h),2.0); - } - } - if (mode!=2 || included!=1) - sum = std::sqrt(sum); - assert(n0) // --contour - for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) - if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) x(3,0); - for (x[2] = MMSP::g0(GRID,2); x[2] < MMSP::g1(GRID,2); x[2]++) - for (x[1] = MMSP::g1(GRID,1)-1; x[1] >= MMSP::g0(GRID,1); x[1]--) - for (x[0] = MMSP::g0(GRID,0); x[0] < MMSP::g1(GRID,0); x[0]++) { - if (x[sliceaxis]!=slicelevel) // clumsy, but effective - continue; - double sum=0.0; - if (mode<2) { // --mag - for (int h=0; h::iterator it=fieldset.begin(); it!=fieldset.end(); it++) { - if (included>1) - sum += pow(GRID(x)[*it],2.0); - else - sum = GRID(x)[*it]; - } - } else if (mode==3) { // --exclude - for (int h=0; h::iterator it=fieldset.find(i); - if (it == fieldset.end()) - sum += pow(GRID(x).value(h),2.0); - } - } - if (mode!=2 || included!=1) - sum = std::sqrt(sum); - assert(n0) // --contour - for (std::set::iterator itl=levelset.begin(); itl!=levelset.end(); itl++) - if (std::fabs(GRID(x)[lvlfield]-*itl)/std::fabs(*itl) -#include"MMSP.hpp" - -template void print_scalars(std::ofstream& fstr, const MMSP::grid& GRID, const int& mode) -{ - if (dim==1) { - MMSP::vector x(1,0); - for (x[0]=MMSP::x0(GRID); x[0] x(2,0); - for (x[1]=MMSP::y0(GRID); x[1] x(3,0); - for (x[2]=MMSP::z0(GRID); x[2] +#include +#include +#include +#include +#include -template void print_vectors(std::ofstream& fstr, const MMSP::grid >& GRID, - const int& mode, const int& field) -{ - if (dim==1) { - MMSP::vector x(1,0); - for (x[0]=MMSP::x0(GRID); x[0]& v = GRID(x); - if (mode==1) { // --mag - double sum = 0.0; - for (int h = 0; h < v.length(); h++) - sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; - } else if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < v.length(); h++) - if (v[h] > v[max]) - max = h; - fstr << max << " "; - } else if (mode==3) { // --field - fstr << v[field] << " "; - } else { - for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; - } - } - } else if (dim==2) { - MMSP::vector x(2,0); - for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - if (mode==1) { // --mag - double sum = 0.0; - for (int h = 0; h < v.length(); h++) - sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; - } else if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < v.length(); h++) - if (v[h] > v[max]) - max = h; - fstr << max << " "; - } else if (mode==3) { // --field - fstr << v[field] << " "; - } else { - for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; - } - } - } - } else if (dim==3) { - MMSP::vector x(3,0); - for (x[2]=MMSP::z0(GRID); x[2]& v = GRID(x); - if (mode==1) { // --mag - double sum = 0.0; - for (int h = 0; h < v.length(); h++) - sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; - } else if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < v.length(); h++) - if (v[h] > v[max]) - max = h; - fstr << max << " "; - } else if (mode==3) { // --field - fstr << v[field] << " "; - } else { - for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; - } - } - } - } - } -} - -template void print_sparses(std::ofstream& fstr, const MMSP::grid >& GRID, - const int& mode, const int& field) -{ - if (dim==1) { - MMSP::vector x(1,0); - for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); - if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < s.length(); h++) - if (s.value(h) > s.value(max)) - max = h; - fstr << s.index(max) << " "; - } else if (mode==3) { // --field - fstr << s[field] << " "; - } else { // --mag is redundant for sparse - double sum = 0.0; - for (int h = 0; h < s.length(); h++) - sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; - } - } - } else if (dim==2) { - MMSP::vector x(2,0); - for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < s.length(); h++) - if (s.value(h) > s.value(max)) - max = h; - fstr << s.index(max) << " "; - } else if (mode==3) { // --field - fstr << s[field] << " "; - } else { // --mag is redundant for sparse - double sum = 0.0; - for (int h = 0; h < s.length(); h++) - sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; - } - } - } - } else if (dim==3) { - MMSP::vector x(3,0); - for (x[2]=MMSP::z0(GRID); x[2]& s = GRID(x); - if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < s.length(); h++) - if (s.value(h) > s.value(max)) - max = h; - fstr << s.index(max) << " "; - } else if (mode==3) { // --field - fstr << s[field] << " "; - } else { // --mag is redundant for sparse - double sum = 0.0; - for (int h = 0; h < s.length(); h++) - sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; - } - } - } - } - } -} +#include"MMSP.hpp" int main(int argc, char* argv[]) { // command line error check @@ -292,31 +107,28 @@ int main(int argc, char* argv[]) { // process each file on the command line - for (int if_idx = dat_idx; if_idx < argc; if_idx++) { - if (if_idx==pvd_idx) + for (int file_idx = dat_idx; file_idx < argc; file_idx++) { + if (file_idx==pvd_idx) continue; - filename.str(""); // clear stream for new input - // file open error check - input.open(argv[if_idx]); - if (!input) { - std::cerr << "File input error: could not open " << argv[if_idx] << ".\n\n"; - exit(-1); - } // generate output file name - filename << std::string(argv[if_idx]).substr(0, std::string(argv[if_idx]).find_last_of(".")) << ".vti"; + filename.str(""); // clear stream for new input + filename << std::string(argv[file_idx]).substr(0, std::string(argv[file_idx]).find_last_of(".")) << ".vti"; + + // write PVD file data + pvdfile << " \n"; + + // skip pre-existing VTK file + if (std::ifstream(filename.str())) // file exists + continue; // file open error check - std::ofstream output(filename.str().c_str()); - if (!output) { - std::cerr << "File output error: could not open "; - std::cerr << filename.str() << "." << std::endl; + input.open(argv[file_idx]); + if (!input) { + std::cerr << "File input error: could not open " << argv[file_idx] << ".\n\n"; exit(-1); } - // write PVD file data - pvdfile << " \n"; - // read data type std::string type; getline(input, type, '\n'); @@ -382,25 +194,6 @@ int main(int argc, char* argv[]) { // ignore trailing endlines input.ignore(10, '\n'); - // output header markup - output << "\n"; - output << "\n"; - if (dim == 1) { - output << " \n"; - } - if (dim == 2) { - output << " \n"; - } - if (dim == 3) { - output << " \n"; - } - // read number of blocks int blocks; input.read(reinterpret_cast(&blocks), sizeof(blocks)); @@ -421,68 +214,6 @@ int main(int argc, char* argv[]) { input.read(reinterpret_cast(&bhi[j]), sizeof(bhi[j])); } - // write header markup - if (dim == 1) - output << " \n"; - if (dim == 2) - output << " \n"; - if (dim == 3) - output << " \n"; - - // write cell data markup - if (scalar_type || flatten>0) { - output << " \n"; - output << " \n"; - output << " \n"; - output << " \n"; - output << " \n"; - else if (flatten==2) // max - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (bool_type) - output << " type=\"UInt8\" format=\"ascii\">\n"; - else if (char_type) - output << " type=\"Int8\" format=\"ascii\">\n"; - else if (unsigned_char_type) - output << " type=\"UInt8\" format=\"ascii\">\n"; - else if (int_type) - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (unsigned_int_type) - output << " type=\"UInt32\" format=\"ascii\">\n"; - else if (long_type) - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (unsigned_long_type) - output << " type=\"UInt32\" format=\"ascii\">\n"; - else if (short_type) - output << " type=\"Int16\" format=\"ascii\">\n"; - else if (unsigned_short_type) - output << " type=\"UInt16\" format=\"ascii\">\n"; - else if (float_type) - output << " type=\"Float32\" format=\"ascii\">\n"; - else if (double_type) - output << " type=\"Float64\" format=\"ascii\">\n"; - else if (long_double_type) - output << " type=\"Float128\" format=\"ascii\">\n"; - - // read grid data unsigned long size, rawSize; input.read(reinterpret_cast(&rawSize), sizeof(rawSize)); // read raw size @@ -515,185 +246,185 @@ int main(int argc, char* argv[]) { } // write grid data - if (not vector_type and not sparse_type) { // must be scalar or built-in + if (scalar_type or (not vector_type and not sparse_type)) { // must be scalar or built-in if (bool_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (unsigned_char_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (char_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (unsigned_int_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (int_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (unsigned_long_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (long_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (unsigned_short_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (short_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (float_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (long_double_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } else if (double_type) { if (dim == 1) { MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 2) { MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } else if (dim == 3) { MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); + scalar_field_to_vtk(filename.str(), GRID, flatten); } } } @@ -703,180 +434,180 @@ int main(int argc, char* argv[]) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_char_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (char_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_int_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (int_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_long_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (long_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_short_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (short_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (float_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (long_double_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (double_type) { if (dim == 1) { MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } } @@ -886,180 +617,180 @@ int main(int argc, char* argv[]) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_char_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (char_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_int_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (int_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_long_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (long_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (unsigned_short_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (short_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (float_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (long_double_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } else if (double_type) { if (dim == 1) { MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 2) { MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } else if (dim == 3) { MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } } @@ -1067,14 +798,7 @@ int main(int argc, char* argv[]) { // clean up delete [] buffer; - // output closing markup - output << "\n"; - output << " \n"; - output << " \n"; - output << " \n"; } // loop for blocks - output << " \n"; - output << "\n"; input.close(); } // loop for files diff --git a/utility/mmsp2tsv.cpp b/utility/mmsp2tsv.cpp index dc12a50..ab0e776 100644 --- a/utility/mmsp2tsv.cpp +++ b/utility/mmsp2tsv.cpp @@ -579,7 +579,7 @@ template void convert_scalars(const MMSP::grid& GRI tsvfil << dx(GRID,0)*x[0]; for (int d=1; d void convert_scalars(const MMSP::grid& GRI tsvfil << dx(GRID,0)*x[0]; for (int d=1; d void convert_scalars(const MMSP::grid& GRI tsvfil << dx(GRID,0)*x[0]; for (int d=1; d -#include -#include -#include -#include"MMSP.hpp" +#include +#include +#include +#include +#include - -template void print_scalars(std::ofstream& fstr, const MMSP::grid& GRID, const int& mode) -{ - if (dim==1) { - MMSP::vector x(1,0); - for (x[0]=MMSP::x0(GRID); x[0] x(2,0); - for (x[1]=MMSP::y0(GRID); x[1] x(3,0); - for (x[2]=MMSP::z0(GRID); x[2] void print_vectors(std::ofstream& fstr, const MMSP::grid >& GRID, - const int& mode, const int& field) -{ - if (dim==1) { - MMSP::vector x(1,0); - for (x[0]=MMSP::x0(GRID); x[0]& v = GRID(x); - if (mode==1) { // --mag - double sum = 0.0; - for (int h = 0; h < v.length(); h++) - sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; - } else if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < v.length(); h++) - if (v[h] > v[max]) - max = h; - fstr << max << " "; - } else if (mode==3) { // --field - fstr << v[field] << " "; - } else { - for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; - } - } - } else if (dim==2) { - MMSP::vector x(2,0); - for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - if (mode==1) { // --mag - double sum = 0.0; - for (int h = 0; h < v.length(); h++) - sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; - } else if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < v.length(); h++) - if (v[h] > v[max]) - max = h; - fstr << max << " "; - } else if (mode==3) { // --field - fstr << v[field] << " "; - } else { - for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; - } - } - } - } else if (dim==3) { - MMSP::vector x(3,0); - for (x[2]=MMSP::z0(GRID); x[2]& v = GRID(x); - if (mode==1) { // --mag - double sum = 0.0; - for (int h = 0; h < v.length(); h++) - sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; - } else if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < v.length(); h++) - if (v[h] > v[max]) - max = h; - fstr << max << " "; - } else if (mode==3) { // --field - fstr << v[field] << " "; - } else { - for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; - } - } - } - } - } -} - -template void print_sparses(std::ofstream& fstr, const MMSP::grid >& GRID, - const int& mode, const int& field) -{ - if (dim==1) { - MMSP::vector x(1,0); - for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); - if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < s.length(); h++) - if (s.value(h) > s.value(max)) - max = h; - fstr << s.index(max) << " "; - } else if (mode==3) { // --field - fstr << s[field] << " "; - } else { // --mag is redundant for sparse - double sum = 0.0; - for (int h = 0; h < s.length(); h++) - sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; - } - } - } else if (dim==2) { - MMSP::vector x(2,0); - for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < s.length(); h++) - if (s.value(h) > s.value(max)) - max = h; - fstr << s.index(max) << " "; - } else if (mode==3) { // --field - fstr << s[field] << " "; - } else { // --mag is redundant for sparse - double sum = 0.0; - for (int h = 0; h < s.length(); h++) - sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; - } - } - } - } else if (dim==3) { - MMSP::vector x(3,0); - for (x[2]=MMSP::z0(GRID); x[2]& s = GRID(x); - if (mode==2) { // --max - // Export index of field with greatest magnitude - int max = 0; - for (int h = 1; h < s.length(); h++) - if (s.value(h) > s.value(max)) - max = h; - fstr << s.index(max) << " "; - } else if (mode==3) { // --field - fstr << s[field] << " "; - } else { // --mag is redundant for sparse - double sum = 0.0; - for (int h = 0; h < s.length(); h++) - sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; - } - } - } - } - } -} +#include "MMSP.hpp" int main(int argc, char* argv[]) { @@ -248,14 +58,6 @@ int main(int argc, char* argv[]) else filename << argv[fileindex+1]; - // file open error check - std::ofstream output(filename.str().c_str()); - if (!output) { - std::cerr << "File output error: could not open "; - std::cerr << filename.str() << "." << std::endl; - exit(-1); - } - // read data type std::string type; getline(input, type, '\n'); @@ -280,17 +82,16 @@ int main(int argc, char* argv[]) bool double_type = (type.find("double") != std::string::npos); bool long_double_type = (type.find("long double") != std::string::npos); - bool scalar_type = (type.find("scalar") != std::string::npos); bool vector_type = (type.find("vector") != std::string::npos); bool sparse_type = (type.find("sparse") != std::string::npos); if (not bool_type and - not char_type and not unsigned_char_type and - not int_type and not unsigned_int_type and - not long_type and not unsigned_long_type and - not short_type and not unsigned_short_type and - not float_type and - not double_type and not long_double_type) { + not char_type and not unsigned_char_type and + not int_type and not unsigned_int_type and + not long_type and not unsigned_long_type and + not short_type and not unsigned_short_type and + not float_type and + not double_type and not long_double_type) { std::cerr << "File input error: unknown grid data type." << std::endl; exit(-1); } @@ -303,726 +104,413 @@ int main(int argc, char* argv[]) exit(-1); } - // read number of fields - int fields; - input >> fields; - - // read grid sizes - int x0[3] = {0, 0, 0}; - int x1[3] = {0, 0, 0}; - for (int i = 0; i < dim; i++) - input >> x0[i] >> x1[i]; - - // read cell spacing - float dx[3] = {1.0, 1.0, 1.0}; - for (int i = 0; i < dim; i++) - input >> dx[i]; - - // ignore trailing endlines - input.ignore(10, '\n'); - - - // determine byte order: 01 AND 01 = 01; 01 AND 10 = 00. - std::string byte_order; - if (0x01 & static_cast(1)) byte_order = "LittleEndian"; - else byte_order = "BigEndian"; - - // output header markup - output << "\n"; - output << "\n"; - - if (dim == 1) { - output << " \n"; - } else if (dim == 2) { - output << " \n"; - } else if (dim == 3) { - output << " \n"; - } else { - std::cerr<<"Error: "<(&blocks), sizeof(blocks)); - - for (int i = 0; i < blocks; i++) { - // read block limits - int lmin[3] = {0, 0, 0}; - int lmax[3] = {0, 0, 0}; - for (int j = 0; j < dim; j++) { - input.read(reinterpret_cast(&lmin[j]), sizeof(lmin[j])); - input.read(reinterpret_cast(&lmax[j]), sizeof(lmax[j])); - } - int blo[3]; - int bhi[3]; - // read boundary conditions - for (int j = 0; j < dim; j++) { - input.read(reinterpret_cast(&blo[j]), sizeof(blo[j])); - input.read(reinterpret_cast(&bhi[j]), sizeof(bhi[j])); - } - - // write header markup - if (dim == 1) - output << " \n"; - if (dim == 2) - output << " \n"; - if (dim == 3) - output << " \n"; - - // write cell data markup - if (scalar_type || flatten>0) { - output << " \n"; - output << " \n"; - output << " \n"; - output << " \n"; - output << " \n"; - else if (flatten==2) // max - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (bool_type) - output << " type=\"UInt8\" format=\"ascii\">\n"; - else if (char_type) - output << " type=\"Int8\" format=\"ascii\">\n"; - else if (unsigned_char_type) - output << " type=\"UInt8\" format=\"ascii\">\n"; - else if (int_type) - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (unsigned_int_type) - output << " type=\"UInt32\" format=\"ascii\">\n"; - else if (long_type) - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (unsigned_long_type) - output << " type=\"UInt32\" format=\"ascii\">\n"; - else if (short_type) - output << " type=\"Int16\" format=\"ascii\">\n"; - else if (unsigned_short_type) - output << " type=\"UInt16\" format=\"ascii\">\n"; - else if (float_type) - output << " type=\"Float32\" format=\"ascii\">\n"; - else if (double_type) - output << " type=\"Float64\" format=\"ascii\">\n"; - else if (long_double_type) - output << " type=\"Float128\" format=\"ascii\">\n"; - - - // read grid data - unsigned long size, rawSize; - input.read(reinterpret_cast(&rawSize), sizeof(rawSize)); // read raw size - input.read(reinterpret_cast(&size), sizeof(size)); // read compressed size - char* compressed_buffer = new char[size]; - input.read(compressed_buffer, size); - char* buffer = NULL; - if (size != rawSize) { - // Decompress data - buffer = new char[rawSize]; - int status; - status = uncompress(reinterpret_cast(buffer), &rawSize, reinterpret_cast(compressed_buffer), size); - switch(status) { - case Z_OK: - break; - case Z_MEM_ERROR: - std::cerr << "Uncompress: out of memory." << std::endl; - exit(1); - break; - case Z_BUF_ERROR: - std::cerr << "Uncompress: output buffer wasn't large enough." << std::endl; - exit(1); - break; + // write grid data + if (not vector_type and not sparse_type) { // must be scalar or built-in + if (bool_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (unsigned_char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (unsigned_int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (unsigned_long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (unsigned_short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (float_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (long_double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } + } else if (double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + scalar_field_to_vtk(filename.str(), GRID, flatten); } - delete [] compressed_buffer; - compressed_buffer = NULL; - } else { - buffer = compressed_buffer; - compressed_buffer = NULL; } + } - // write grid data - if (not vector_type and not sparse_type) { // must be scalar or built-in - if (bool_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (float_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (long_double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - } - - else if (vector_type) { - if (bool_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (float_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (long_double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } + else if (vector_type) { + if (bool_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (float_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (long_double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + vector_field_to_vtk(filename.str(), GRID, flatten, field); } } + } - else if (sparse_type) { - if (bool_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (float_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (long_double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } + else if (sparse_type) { + if (bool_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (unsigned_short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (float_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (long_double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } + } else if (double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + sparse_field_to_vtk(filename.str(), GRID, flatten, field); } } - - // clean up - delete [] buffer; - - // write closing markup - output << "\n"; - output << " \n"; - output << " \n"; - output << " \n"; } -// output closing markup - output << " \n"; - output << "\n"; } diff --git a/utility/mmsp2xyz.cpp b/utility/mmsp2xyz.cpp index ca617cc..178b38a 100644 --- a/utility/mmsp2xyz.cpp +++ b/utility/mmsp2xyz.cpp @@ -231,16 +231,8 @@ int main(int argc, char* argv[]) // write grid data if (scalar_type or (not vector_type and not sparse_type)) { // must be scalar or built-in if (bool_type) { - if (dim == 1) { - MMSP::grid<1,bool> GRID(argv[datindex]); - convert_scalars(GRID, mode, normal, levelset, lvlfield, contol, xyzfil); - } else if (dim == 2) { - MMSP::grid<2,bool> GRID(argv[datindex]); - convert_scalars(GRID, mode, normal, levelset, lvlfield, contol, xyzfil); - } else if (dim == 3) { - MMSP::grid<3,bool> GRID(argv[datindex]); - convert_scalars(GRID, mode, normal, levelset, lvlfield, contol, xyzfil); - } + std::cerr << "Error: boolean fields are incompatible with " << argv[0] << std::endl; + MMSP::Abort(-1); } else if (unsigned_char_type) { if (dim == 1) { @@ -378,16 +370,8 @@ int main(int argc, char* argv[]) else if (vector_type) { if (bool_type) { - if (dim == 1) { - MMSP::grid<1,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, normal, levelset, lvlfield, contol, fieldset, xyzfil); - } else if (dim == 2) { - MMSP::grid<2,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, normal, levelset, lvlfield, contol, fieldset, xyzfil); - } else if (dim == 3) { - MMSP::grid<3,MMSP::vector > GRID(argv[datindex]); - convert_vectors(GRID, mode, normal, levelset, lvlfield, contol, fieldset, xyzfil); - } + std::cerr << "Error: boolean fields are incompatible with " << argv[0] << std::endl; + MMSP::Abort(-1); } else if (unsigned_char_type) { if (dim == 1) { @@ -525,16 +509,8 @@ int main(int argc, char* argv[]) else if (sparse_type) { if (bool_type) { - if (dim == 1) { - MMSP::grid<1,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, normal, levelset, lvlfield, contol, fieldset, xyzfil); - } else if (dim == 2) { - MMSP::grid<2,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, normal, levelset, lvlfield, contol, fieldset, xyzfil); - } else if (dim == 3) { - MMSP::grid<3,MMSP::sparse > GRID(argv[datindex]); - convert_sparses(GRID, mode, normal, levelset, lvlfield, contol, fieldset, xyzfil); - } + std::cerr << "Error: boolean fields are incompatible with " << argv[0] << std::endl; + MMSP::Abort(-1); } else if (unsigned_char_type) { if (dim == 1) { @@ -679,9 +655,9 @@ template void convert_scalars(const MMSP::grid& GRI if (dim==1) { for (int n=0; n::iterator it=levelset.begin(); excluded && it!=levelset.end(); it++) if (std::fabs(val-*it)/std::fabs(*it) void convert_scalars(const MMSP::grid& GRI } else if (dim==2) { for (int n=0; n::iterator it=levelset.begin(); excluded && it!=levelset.end(); it++) if (std::fabs(val-*it)/std::fabs(*it) void convert_scalars(const MMSP::grid& GRI } else if (dim==3) { for (int n=0; n::iterator it=levelset.begin(); excluded && it!=levelset.end(); it++) if (std::fabs(val-*it)/std::fabs(*it)" > ${PVD} +echo "" >> ${PVD} +echo " " >> ${PVD} + +for ((i=0;i" >> ${PVD} +done + +echo " " >> ${PVD} +echo "" >> ${PVD}