diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..afc69a2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 2.6) + +project(CosmoToolbox) + +option(BUILD_SHARED_LIBS "Build shared libraries." OFF) + +find_path(NETCDF_INCLUDE_PATH NAMES netcdf.h) +find_path(GSL_INCLUDE_PATH NAMES gsl/gsl_blas.h) + +find_library(NETCDF_LIBRARY netcdf) +find_library(NETCDFCPP_LIBRARY netcdf_c++) +find_library(GSL_LIBRARY gsl) +find_library(GSLCBLAS_LIBRARY gslcblas) + + + +include(FindPackageHandleStandardArgs) +set(NETCDF_FIND_REQUIRED TRUE) +set(GSL_FIND_REQUIRED TRUE) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(NetCDF DEFAULT_MSG NETCDF_LIBRARY NETCDFCPP_LIBRARY NETCDF_INCLUDE_PATH) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSL DEFAULT_MSG GSL_LIBRARY GSLCBLAS_LIBRARY GSL_INCLUDE_PATH) + + +# CPACK Configuration +SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A toolbox for impatient cosmologists") +SET(CPACK_PACKAGE_VENDOR "Guilhem Lavaux") +SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE_CeCILL_V2") +SET(CPACK_PACKAGE_VERSION_MAJOR "1") +SET(CPACK_PACKAGE_VERSION_MINOR "0") +SET(CPACK_PACKAGE_VERSION_PATCH "0") +SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CosmoToolbox-${GalaxExplorer_VERSION_MAJOR}.${GalaxExplorer_VERSION_MINOR}") +SET(CPACK_STRIP_FILES "lib/libCosmoTool.so") +SET(CPACK_SOURCE_IGNORE_FILES +"/CVS/;/\\\\.git/;/\\\\.svn/;\\\\.swp$;\\\\.#;/#;.*~;cscope.*;/CMakeFiles/;.*\\\\.cmake;Makefile") + +add_subdirectory(src) +add_subdirectory(sample) + +include(CPack) diff --git a/LICENCE_CeCILL_V2 b/LICENCE_CeCILL_V2 new file mode 100644 index 0000000..fcc8df2 --- /dev/null +++ b/LICENCE_CeCILL_V2 @@ -0,0 +1,506 @@ + +CeCILL FREE SOFTWARE LICENSE AGREEMENT + + + Notice + +This Agreement is a Free Software license agreement that is the result +of discussions between its authors in order to ensure compliance with +the two main principles guiding its drafting: + + * firstly, compliance with the principles governing the distribution + of Free Software: access to source code, broad rights granted to + users, + * secondly, the election of a governing law, French law, with which + it is conformant, both as regards the law of torts and + intellectual property law, and the protection that it offers to + both authors and holders of the economic rights over software. + +The authors of the CeCILL (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) +license are: + +Commissariat à l'Energie Atomique - CEA, a public scientific, technical +and industrial research establishment, having its principal place of +business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. + +Centre National de la Recherche Scientifique - CNRS, a public scientific +and technological establishment, having its principal place of business +at 3 rue Michel-Ange, 75794 Paris cedex 16, France. + +Institut National de Recherche en Informatique et en Automatique - +INRIA, a public scientific and technological establishment, having its +principal place of business at Domaine de Voluceau, Rocquencourt, BP +105, 78153 Le Chesnay cedex, France. + + + Preamble + +The purpose of this Free Software license agreement is to grant users +the right to modify and redistribute the software governed by this +license within the framework of an open source distribution model. + +The exercising of these rights is conditional upon certain obligations +for users so as to preserve this status for all subsequent redistributions. + +In consideration of access to the source code and the rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors only have limited liability. + +In this respect, the risks associated with loading, using, modifying +and/or developing or reproducing the software by the user are brought to +the user's attention, given its Free Software status, which may make it +complicated to use, with the result that its use is reserved for +developers and experienced professionals having in-depth computer +knowledge. Users are therefore encouraged to load and test the +suitability of the software as regards their requirements in conditions +enabling the security of their systems and/or data to be ensured and, +more generally, to use and operate it in the same conditions of +security. This Agreement may be freely reproduced and published, +provided it is not altered, and that no provisions are either added or +removed herefrom. + +This Agreement may apply to any or all software for which the holder of +the economic rights decides to submit the use thereof to its provisions. + + + Article 1 - DEFINITIONS + +For the purpose of this Agreement, when the following expressions +commence with a capital letter, they shall have the following meaning: + +Agreement: means this license agreement, and its possible subsequent +versions and annexes. + +Software: means the software in its Object Code and/or Source Code form +and, where applicable, its documentation, "as is" when the Licensee +accepts the Agreement. + +Initial Software: means the Software in its Source Code and possibly its +Object Code form and, where applicable, its documentation, "as is" when +it is first distributed under the terms and conditions of the Agreement. + +Modified Software: means the Software modified by at least one +Contribution. + +Source Code: means all the Software's instructions and program lines to +which access is required so as to modify the Software. + +Object Code: means the binary files originating from the compilation of +the Source Code. + +Holder: means the holder(s) of the economic rights over the Initial +Software. + +Licensee: means the Software user(s) having accepted the Agreement. + +Contributor: means a Licensee having made at least one Contribution. + +Licensor: means the Holder, or any other individual or legal entity, who +distributes the Software under the Agreement. + +Contribution: means any or all modifications, corrections, translations, +adaptations and/or new functions integrated into the Software by any or +all Contributors, as well as any or all Internal Modules. + +Module: means a set of sources files including their documentation that +enables supplementary functions or services in addition to those offered +by the Software. + +External Module: means any or all Modules, not derived from the +Software, so that this Module and the Software run in separate address +spaces, with one calling the other when they are run. + +Internal Module: means any or all Module, connected to the Software so +that they both execute in the same address space. + +GNU GPL: means the GNU General Public License version 2 or any +subsequent version, as published by the Free Software Foundation Inc. + +Parties: mean both the Licensee and the Licensor. + +These expressions may be used both in singular and plural form. + + + Article 2 - PURPOSE + +The purpose of the Agreement is the grant by the Licensor to the +Licensee of a non-exclusive, transferable and worldwide license for the +Software as set forth in Article 5 hereinafter for the whole term of the +protection granted by the rights over said Software. + + + Article 3 - ACCEPTANCE + +3.1 The Licensee shall be deemed as having accepted the terms and +conditions of this Agreement upon the occurrence of the first of the +following events: + + * (i) loading the Software by any or all means, notably, by + downloading from a remote server, or by loading from a physical + medium; + * (ii) the first time the Licensee exercises any of the rights + granted hereunder. + +3.2 One copy of the Agreement, containing a notice relating to the +characteristics of the Software, to the limited warranty, and to the +fact that its use is restricted to experienced users has been provided +to the Licensee prior to its acceptance as set forth in Article 3.1 +hereinabove, and the Licensee hereby acknowledges that it has read and +understood it. + + + Article 4 - EFFECTIVE DATE AND TERM + + + 4.1 EFFECTIVE DATE + +The Agreement shall become effective on the date when it is accepted by +the Licensee as set forth in Article 3.1. + + + 4.2 TERM + +The Agreement shall remain in force for the entire legal term of +protection of the economic rights over the Software. + + + Article 5 - SCOPE OF RIGHTS GRANTED + +The Licensor hereby grants to the Licensee, who accepts, the following +rights over the Software for any or all use, and for the term of the +Agreement, on the basis of the terms and conditions set forth hereinafter. + +Besides, if the Licensor owns or comes to own one or more patents +protecting all or part of the functions of the Software or of its +components, the Licensor undertakes not to enforce the rights granted by +these patents against successive Licensees using, exploiting or +modifying the Software. If these patents are transferred, the Licensor +undertakes to have the transferees subscribe to the obligations set +forth in this paragraph. + + + 5.1 RIGHT OF USE + +The Licensee is authorized to use the Software, without any limitation +as to its fields of application, with it being hereinafter specified +that this comprises: + + 1. permanent or temporary reproduction of all or part of the Software + by any or all means and in any or all form. + + 2. loading, displaying, running, or storing the Software on any or + all medium. + + 3. entitlement to observe, study or test its operation so as to + determine the ideas and principles behind any or all constituent + elements of said Software. This shall apply when the Licensee + carries out any or all loading, displaying, running, transmission + or storage operation as regards the Software, that it is entitled + to carry out hereunder. + + + 5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS + +The right to make Contributions includes the right to translate, adapt, +arrange, or make any or all modifications to the Software, and the right +to reproduce the resulting software. + +The Licensee is authorized to make any or all Contributions to the +Software provided that it includes an explicit notice that it is the +author of said Contribution and indicates the date of the creation thereof. + + + 5.3 RIGHT OF DISTRIBUTION + +In particular, the right of distribution includes the right to publish, +transmit and communicate the Software to the general public on any or +all medium, and by any or all means, and the right to market, either in +consideration of a fee, or free of charge, one or more copies of the +Software by any means. + +The Licensee is further authorized to distribute copies of the modified +or unmodified Software to third parties according to the terms and +conditions set forth hereinafter. + + + 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION + +The Licensee is authorized to distribute true copies of the Software in +Source Code or Object Code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's + warranty and liability as set forth in Articles 8 and 9, + +and that, in the event that only the Object Code of the Software is +redistributed, the Licensee allows future Licensees unhindered access to +the full Source Code of the Software by indicating how to access it, it +being understood that the additional cost of acquiring the Source Code +shall not exceed the cost of transferring the data. + + + 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE + +When the Licensee makes a Contribution to the Software, the terms and +conditions for the distribution of the resulting Modified Software +become subject to all the provisions of this Agreement. + +The Licensee is authorized to distribute the Modified Software, in +source code or object code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's + warranty and liability as set forth in Articles 8 and 9, + +and that, in the event that only the object code of the Modified +Software is redistributed, the Licensee allows future Licensees +unhindered access to the full source code of the Modified Software by +indicating how to access it, it being understood that the additional +cost of acquiring the source code shall not exceed the cost of +transferring the data. + + + 5.3.3 DISTRIBUTION OF EXTERNAL MODULES + +When the Licensee has developed an External Module, the terms and +conditions of this Agreement do not apply to said External Module, that +may be distributed under a separate license agreement. + + + 5.3.4 COMPATIBILITY WITH THE GNU GPL + +The Licensee can include a code that is subject to the provisions of one +of the versions of the GNU GPL in the Modified or unmodified Software, +and distribute that entire code under the terms of the same version of +the GNU GPL. + +The Licensee can include the Modified or unmodified Software in a code +that is subject to the provisions of one of the versions of the GNU GPL, +and distribute that entire code under the terms of the same version of +the GNU GPL. + + + Article 6 - INTELLECTUAL PROPERTY + + + 6.1 OVER THE INITIAL SOFTWARE + +The Holder owns the economic rights over the Initial Software. Any or +all use of the Initial Software is subject to compliance with the terms +and conditions under which the Holder has elected to distribute its work +and no one shall be entitled to modify the terms and conditions for the +distribution of said Initial Software. + +The Holder undertakes that the Initial Software will remain ruled at +least by this Agreement, for the duration set forth in Article 4.2. + + + 6.2 OVER THE CONTRIBUTIONS + +The Licensee who develops a Contribution is the owner of the +intellectual property rights over this Contribution as defined by +applicable law. + + + 6.3 OVER THE EXTERNAL MODULES + +The Licensee who develops an External Module is the owner of the +intellectual property rights over this External Module as defined by +applicable law and is free to choose the type of agreement that shall +govern its distribution. + + + 6.4 JOINT PROVISIONS + +The Licensee expressly undertakes: + + 1. not to remove, or modify, in any manner, the intellectual property + notices attached to the Software; + + 2. to reproduce said notices, in an identical manner, in the copies + of the Software modified or not. + +The Licensee undertakes not to directly or indirectly infringe the +intellectual property rights of the Holder and/or Contributors on the +Software and to take, where applicable, vis-à-vis its staff, any and all +measures required to ensure respect of said intellectual property rights +of the Holder and/or Contributors. + + + Article 7 - RELATED SERVICES + +7.1 Under no circumstances shall the Agreement oblige the Licensor to +provide technical assistance or maintenance services for the Software. + +However, the Licensor is entitled to offer this type of services. The +terms and conditions of such technical assistance, and/or such +maintenance, shall be set forth in a separate instrument. Only the +Licensor offering said maintenance and/or technical assistance services +shall incur liability therefor. + +7.2 Similarly, any Licensor is entitled to offer to its licensees, under +its sole responsibility, a warranty, that shall only be binding upon +itself, for the redistribution of the Software and/or the Modified +Software, under terms and conditions that it is free to decide. Said +warranty, and the financial terms and conditions of its application, +shall be subject of a separate instrument executed between the Licensor +and the Licensee. + + + Article 8 - LIABILITY + +8.1 Subject to the provisions of Article 8.2, the Licensee shall be +entitled to claim compensation for any direct loss it may have suffered +from the Software as a result of a fault on the part of the relevant +Licensor, subject to providing evidence thereof. + +8.2 The Licensor's liability is limited to the commitments made under +this Agreement and shall not be incurred as a result of in particular: +(i) loss due the Licensee's total or partial failure to fulfill its +obligations, (ii) direct or consequential loss that is suffered by the +Licensee due to the use or performance of the Software, and (iii) more +generally, any consequential loss. In particular the Parties expressly +agree that any or all pecuniary or business loss (i.e. loss of data, +loss of profits, operating loss, loss of customers or orders, +opportunity cost, any disturbance to business activities) or any or all +legal proceedings instituted against the Licensee by a third party, +shall constitute consequential loss and shall not provide entitlement to +any or all compensation from the Licensor. + + + Article 9 - WARRANTY + +9.1 The Licensee acknowledges that the scientific and technical +state-of-the-art when the Software was distributed did not enable all +possible uses to be tested and verified, nor for the presence of +possible defects to be detected. In this respect, the Licensee's +attention has been drawn to the risks associated with loading, using, +modifying and/or developing and reproducing the Software which are +reserved for experienced users. + +The Licensee shall be responsible for verifying, by any or all means, +the suitability of the product for its requirements, its good working +order, and for ensuring that it shall not cause damage to either persons +or properties. + +9.2 The Licensor hereby represents, in good faith, that it is entitled +to grant all the rights over the Software (including in particular the +rights set forth in Article 5). + +9.3 The Licensee acknowledges that the Software is supplied "as is" by +the Licensor without any other express or tacit warranty, other than +that provided for in Article 9.2 and, in particular, without any warranty +as to its commercial value, its secured, safe, innovative or relevant +nature. + +Specifically, the Licensor does not warrant that the Software is free +from any error, that it will operate without interruption, that it will +be compatible with the Licensee's own equipment and software +configuration, nor that it will meet the Licensee's requirements. + +9.4 The Licensor does not either expressly or tacitly warrant that the +Software does not infringe any third party intellectual property right +relating to a patent, software or any other property right. Therefore, +the Licensor disclaims any and all liability towards the Licensee +arising out of any or all proceedings for infringement that may be +instituted in respect of the use, modification and redistribution of the +Software. Nevertheless, should such proceedings be instituted against +the Licensee, the Licensor shall provide it with technical and legal +assistance for its defense. Such technical and legal assistance shall be +decided on a case-by-case basis between the relevant Licensor and the +Licensee pursuant to a memorandum of understanding. The Licensor +disclaims any and all liability as regards the Licensee's use of the +name of the Software. No warranty is given as regards the existence of +prior rights over the name of the Software or as regards the existence +of a trademark. + + + Article 10 - TERMINATION + +10.1 In the event of a breach by the Licensee of its obligations +hereunder, the Licensor may automatically terminate this Agreement +thirty (30) days after notice has been sent to the Licensee and has +remained ineffective. + +10.2 A Licensee whose Agreement is terminated shall no longer be +authorized to use, modify or distribute the Software. However, any +licenses that it may have granted prior to termination of the Agreement +shall remain valid subject to their having been granted in compliance +with the terms and conditions hereof. + + + Article 11 - MISCELLANEOUS + + + 11.1 EXCUSABLE EVENTS + +Neither Party shall be liable for any or all delay, or failure to +perform the Agreement, that may be attributable to an event of force +majeure, an act of God or an outside cause, such as defective +functioning or interruptions of the electricity or telecommunications +networks, network paralysis following a virus attack, intervention by +government authorities, natural disasters, water damage, earthquakes, +fire, explosions, strikes and labor unrest, war, etc. + +11.2 Any failure by either Party, on one or more occasions, to invoke +one or more of the provisions hereof, shall under no circumstances be +interpreted as being a waiver by the interested Party of its right to +invoke said provision(s) subsequently. + +11.3 The Agreement cancels and replaces any or all previous agreements, +whether written or oral, between the Parties and having the same +purpose, and constitutes the entirety of the agreement between said +Parties concerning said purpose. No supplement or modification to the +terms and conditions hereof shall be effective as between the Parties +unless it is made in writing and signed by their duly authorized +representatives. + +11.4 In the event that one or more of the provisions hereof were to +conflict with a current or future applicable act or legislative text, +said act or legislative text shall prevail, and the Parties shall make +the necessary amendments so as to comply with said act or legislative +text. All other provisions shall remain effective. Similarly, invalidity +of a provision of the Agreement, for any reason whatsoever, shall not +cause the Agreement as a whole to be invalid. + + + 11.5 LANGUAGE + +The Agreement is drafted in both French and English and both versions +are deemed authentic. + + + Article 12 - NEW VERSIONS OF THE AGREEMENT + +12.1 Any person is authorized to duplicate and distribute copies of this +Agreement. + +12.2 So as to ensure coherence, the wording of this Agreement is +protected and may only be modified by the authors of the License, who +reserve the right to periodically publish updates or new versions of the +Agreement, each with a separate number. These subsequent versions may +address new issues encountered by Free Software. + +12.3 Any Software distributed under a given version of the Agreement may +only be subsequently distributed under the same version of the Agreement +or a subsequent version, subject to the provisions of Article 5.3.4. + + + Article 13 - GOVERNING LAW AND JURISDICTION + +13.1 The Agreement is governed by French law. The Parties agree to +endeavor to seek an amicable solution to any disagreements or disputes +that may arise during the performance of the Agreement. + +13.2 Failing an amicable solution within two (2) months as from their +occurrence, and unless emergency proceedings are necessary, the +disagreements or disputes shall be referred to the Paris Courts having +jurisdiction, by the more diligent Party. + + +Version 2.0 dated 2006-09-05. diff --git a/lib/Makefile b/lib/Makefile deleted file mode 100644 index baa976a..0000000 --- a/lib/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -SHLIBS= libCosmoTool.so -SOURCES= loadRamses.cpp yorick.cpp miniargs.cpp fortran.cpp interpolate.cpp load_data.cpp powerSpectrum.cpp octTree.cpp loadGadget.cpp -LIBS= -lnetcdf_c++ -lnetcdf -lgsl -lgslcblas -lm - -include config.mk - -VPATH=../src - -all: $(SHLIBS) - -libCosmoTool.so: loadRamses.o yorick.o miniargs.o fortran.o interpolate.o load_data.o powerSpectrum.o octTree.o loadGadget.o - -depend: $(SOURCES) - @echo "[DEPENDS] $^" - @$(CC) $(CPPFLAGS) -M -MM $^ > .mydepends - -install: - @mkdir -p ../install/lib - @mkdir -p ../install/include/CosmoTool - @echo "Copying libraries" - @cp libCosmoTool.so ../install/lib - @echo "Copying header files" - @cp ../src/*.hpp ../install/include/CosmoTool - @cp ../src/*.tcc ../install/include/CosmoTool - -distclean: clean - @rm -f .mydepends - -clean: - @rm -f *.o - @rm -f $(PROGS) - -.mydepends: depend Makefile config.mk - -%.so: - @echo "[LINK SHARED] $@" - @$(CXX) -shared -o $@ $^ $(LDFLAGS) $(LIBS) - -%.prog: - @echo "[L] $@" - @$(CXX) -o $@ $^ $(LDFLAGS) $(LIBS) - -%.o: %.c - @echo "[C] $< ..." - @$(CC) -c -fPIC -o $@ $< $(CPPFLAGS) $(CFLAGS) - -%.o: %.cpp - @echo "[C++] $< ..." - @$(CXX) -c -fPIC -o $@ $< $(CPPFLAGS) $(CXXFLAGS) - -include .mydepends diff --git a/lib/config.mk b/lib/config.mk deleted file mode 100644 index b7d6f8b..0000000 --- a/lib/config.mk +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CXX=g++ -CFLAGS=-ggdb -O0 -CXXFLAGS=-ggdb -O0 -LDFLAGS= -CPPFLAGS= diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..1bffaaa --- /dev/null +++ b/sample/CMakeLists.txt @@ -0,0 +1,20 @@ +SET(tolink CosmoTool ${GSL_LIBRARY} ${GSLCBLAS_LIBRARY}) +include_directories(${CMAKE_SOURCE_DIR}/src) + +add_executable(testBQueue testBQueue.cpp) +target_link_libraries(testBQueue ${tolink}) + +add_executable(testInterpolate testInterpolate.cpp) +target_link_libraries(testInterpolate ${tolink}) + +add_executable(testSmooth testSmooth.cpp) +target_link_libraries(testSmooth ${tolink}) + +add_executable(testkd testkd.cpp) +target_link_libraries(testkd ${tolink}) + +add_executable(testkd2 testkd2.cpp) +target_link_libraries(testkd2 ${tolink}) + +add_executable(testDelaunay testDelaunay.cpp) +target_link_libraries(testDelaunay ${tolink}) diff --git a/sample/testBQueue.cpp b/sample/testBQueue.cpp index 9187e24..822cd6b 100644 --- a/sample/testBQueue.cpp +++ b/sample/testBQueue.cpp @@ -5,7 +5,7 @@ using namespace std; int main(int argc, char **argv) { - CosmoTool::BoundedQueue bq(4); + CosmoTool::BoundedQueue bq(4, 100000.); for (int i = 10; i >= 0; i--) { diff --git a/sample/testDelaunay.cpp b/sample/testDelaunay.cpp new file mode 100644 index 0000000..bc2f6a7 --- /dev/null +++ b/sample/testDelaunay.cpp @@ -0,0 +1,28 @@ +#include +#include "dinterpolate.hpp" + +#define NX 10 +#define NY 10 + +using namespace std; +using namespace CosmoTool; + +typedef DelaunayInterpolate myTriangle; + +int main() +{ + myTriangle::CoordType pos[] = { {0,0}, {1,0}, {0,1}, {1, 1} } ; + double vals[] = { 0, 1, 1, 0 }; + uint32_t simplex[] = { 0, 1, 2, 3, 1, 2 }; + + myTriangle t(&pos[0], &vals[0], &simplex[0], 4, 2); + + for (uint32_t iy = 0; iy <= NY; iy++) { + for (uint32_t ix = 0; ix <= NX; ix++) { + myTriangle::CoordType inter = { ix *1.0/ NX, iy *1.0/NY }; + cout << inter[1] << " " << inter[0] << " " << t.computeValue(inter) << endl; + } + cout << endl; + } + return 0; +} diff --git a/sample/testInterpolate.cpp b/sample/testInterpolate.cpp new file mode 100644 index 0000000..603de20 --- /dev/null +++ b/sample/testInterpolate.cpp @@ -0,0 +1,30 @@ +#include +#include "interpolate3d.hpp" + +using namespace std; +using namespace CosmoTool; + +int main() +{ + VectorField *vectors = new VectorField[8]; + + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) + for (int k = 0; k < 2; k++) + { + int idx = i + 2*(j + 2*k); + vectors[idx].vec[0] = i; + vectors[idx].vec[1] = j; + } + + GridSampler > sampler(vectors, 2, 2, 2, 2); + Interpolate3D > > inter(sampler); + + VectorField v = inter.get(0.5,0.5,0.5); + VectorField v2 = inter.get(1.5,1.5,1.5); + + cout << v.vec[0] << " " << v.vec[1] << endl; + cout << v2.vec[0] << " " << v2.vec[1] << endl; + + return 0; +} diff --git a/sample/testSmooth.cpp b/sample/testSmooth.cpp new file mode 100644 index 0000000..d1c94a9 --- /dev/null +++ b/sample/testSmooth.cpp @@ -0,0 +1,68 @@ +#include +#include "sphSmooth.hpp" +#include "yorick.hpp" +#include "mykdtree.hpp" + +using namespace std; +using namespace CosmoTool; + +#define NX 1024 +#define ND 2 + +typedef SPHSmooth MySmooth; +typedef MySmooth::SPHTree MyTree; +typedef MySmooth::SPHNode MyNode; +typedef MySmooth::SPHCell MyCell; + +double unit_fun(const char& c) +{ + return 1.0; +} + +int main() +{ + uint32_t Ncells = 10000; + MyCell *cells = new MyCell[Ncells]; + + for (int i = 0; i < Ncells; i++) + { + cells[i].active = true; + for (int l = 0; l < ND; l++) + cells[i].coord[l] = drand48(); + cells[i].val.weight = 0; + } + + MyTree tree(cells, Ncells); + MySmooth smooth(&tree, 16); + + for (uint32_t iy = 0; iy < NX; iy++) + { + cout << "iy=" << iy << endl; + for (uint32_t ix = 0; ix < NX; ix++) + { + MyTree::coords c = { 1.0*ix/NX, 1.0*iy/NX }; + smooth.fetchNeighbours(c); + smooth.addGridSite(c); + } + } + + + uint32_t dims[] = { NX, NX }; + ProgressiveOutput out = + ProgressiveOutput::saveArrayProgressive("out.nc", dims, 2); + for (uint32_t iy = 0; iy < NX; iy++) + { + cout << "iy=" << iy << endl; + for (uint32_t ix = 0; ix < NX; ix++) + { + MyTree::coords c = { 1.0*ix/NX, 1.0*iy/NX }; + smooth.fetchNeighbours(c); + out.put(smooth.computeSmoothedValue(c, unit_fun)); + + + } + } + + + return 0; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..f89d2c4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,45 @@ +SET(CosmoTool_SRCS + fortran.cpp + interpolate.cpp + load_data.cpp + loadGadget.cpp + loadRamses.cpp + octTree.cpp + powerSpectrum.cpp + yorick.cpp + miniargs.cpp +) + +SET(CosmoTool_SRCS ${CosmoTool_SRCS} + bqueue.hpp + config.hpp + dinterpolate.hpp + field.hpp + fixArray.hpp + fortran.hpp + interpolate3d.hpp + interpolate.hpp + kdtree_leaf.hpp + load_data.hpp + loadGadget.hpp + loadRamses.hpp + loadSimu.hpp + miniargs.hpp + mykdtree.hpp + octTree.hpp + powerSpectrum.hpp + sparseGrid.hpp + sphSmooth.hpp + yorick.hpp +) + +add_library(CosmoTool ${CosmoTool_SRCS}) +target_link_libraries(CosmoTool ${NETCDF_LIBRARY} ${NETCDFCPP_LIBRARY} ${GSL_LIBRARY} ${GSLCBLAS_LIBRARY}) + +install(TARGETS CosmoTool + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) +install(DIRECTORY . DESTINATION include/CosmoTool + FILES_MATCHING PATTERN "*.hpp") +install(DIRECTORY . DESTINATION include/CosmoTool + FILES_MATCHING PATTERN "*.tcc") diff --git a/src/loadGadget.cpp b/src/loadGadget.cpp index 03f0b78..a8048e6 100644 --- a/src/loadGadget.cpp +++ b/src/loadGadget.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,6 +7,7 @@ #include "fortran.hpp" using namespace CosmoTool; +using namespace std; PurePositionData *CosmoTool::loadGadgetPosition(const char *fname) { @@ -93,33 +95,54 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) return 0; } - f->beginCheckpoint(); - for (int i = 0; i < 6; i++) - h.npart[i] = f->readInt32(); - for (int i = 0; i < 6; i++) - h.mass[i] = f->readReal64(); - data->time = h.time = f->readReal64(); - h.redshift = f->readReal64(); - h.flag_sfr = f->readInt32(); - h.flag_feedback = f->readInt32(); - for (int i = 0; i < 6; i++) - h.npartTotal[i] = f->readInt32(); - h.flag_cooling = f->readInt32(); - h.num_files = f->readInt32(); - data->BoxSize = h.BoxSize = f->readReal64(); - h.Omega0 = f->readReal64(); - h.OmegaLambda = f->readReal64(); - h.HubbleParam = f->readReal64(); - f->endCheckpoint(true); - long NumPart = 0, NumPartTotal = 0; - for(int k=0; k<5; k++) + + try { - NumPart += h.npart[k]; - NumPartTotal += (id < 0) ? h.npart[k] : h.npartTotal[k]; + f->beginCheckpoint(); + for (int i = 0; i < 6; i++) + h.npart[i] = f->readInt32(); + for (int i = 0; i < 6; i++) + h.mass[i] = f->readReal64(); + data->time = h.time = f->readReal64(); + h.redshift = f->readReal64(); + h.flag_sfr = f->readInt32(); + h.flag_feedback = f->readInt32(); + for (int i = 0; i < 6; i++) + h.npartTotal[i] = f->readInt32(); + h.flag_cooling = f->readInt32(); + h.num_files = f->readInt32(); + data->BoxSize = h.BoxSize = f->readReal64(); + h.Omega0 = f->readReal64(); + h.OmegaLambda = f->readReal64(); + h.HubbleParam = f->readReal64(); + f->endCheckpoint(true); + + for(int k=0; k<6; k++) + { + NumPart += h.npart[k]; + NumPartTotal += (id < 0) ? h.npart[k] : h.npartTotal[k]; + } + data->NumPart = NumPart; + data->TotalNumPart = NumPartTotal; + } + catch (const InvalidUnformattedAccess& e) + { + cerr << "Invalid format while reading header" << endl; + delete data; + delete f; + return 0; + } + + if (loadflags & NEED_TYPE) + { + int p = 0; + + data->type = new int[data->NumPart]; + for (int k = 0; k < 6; k++) + for (int n = 0; n < h.npart[k]; n++,p++) + data->type[p] = k; } - data->NumPart = NumPart; - data->TotalNumPart = NumPartTotal; if (loadflags & NEED_POSITION) { @@ -130,17 +153,27 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) return 0; } } - - f->beginCheckpoint(); - for(int k = 0, p = 0; k < 5; k++) { - for(int n = 0; n < h.npart[k]; n++) { - data->Pos[0][p] = f->readReal32(); - data->Pos[1][p] = f->readReal32(); - data->Pos[2][p] = f->readReal32(); - p++; + + try + { + f->beginCheckpoint(); + for(int k = 0, p = 0; k < 6; k++) { + for(int n = 0; n < h.npart[k]; n++) { + data->Pos[0][p] = f->readReal32(); + data->Pos[1][p] = f->readReal32(); + data->Pos[2][p] = f->readReal32(); + p++; + } + } + f->endCheckpoint(); + } + catch (const InvalidUnformattedAccess& e) + { + cerr << "Invalid format while reading positions" << endl; + delete f; + delete data; + return 0; } - } - f->endCheckpoint(); } else { // Skip positions @@ -153,21 +186,32 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) data->Vel[i] = new float[data->NumPart]; if (data->Vel[i] == 0) { + delete f; delete data; return 0; } } - - f->beginCheckpoint(); - for(int k = 0, p = 0; k < 5; k++) { - for(int n = 0; n < h.npart[k]; n++) { - data->Vel[0][p] = f->readReal32(); - data->Vel[1][p] = f->readReal32(); - data->Vel[2][p] = f->readReal32(); - p++; + + try + { + f->beginCheckpoint(); + for(int k = 0, p = 0; k < 6; k++) { + for(int n = 0; n < h.npart[k]; n++) { + data->Vel[0][p] = f->readReal32(); + data->Vel[1][p] = f->readReal32(); + data->Vel[2][p] = f->readReal32(); + p++; + } + } + f->endCheckpoint(); + } + catch (const InvalidUnformattedAccess& e) + { + cerr << "Invalid format while reading velocities" << endl; + delete f; + delete data; + return 0; } - } - f->endCheckpoint(); // TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!! } else { @@ -177,23 +221,34 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) // Skip ids if (loadflags & NEED_GADGET_ID) { - f->beginCheckpoint(); - data->Id = new int[data->NumPart]; - if (data->Id == 0) + try { + f->beginCheckpoint(); + data->Id = new int[data->NumPart]; + if (data->Id == 0) + { + delete f; + delete data; + return 0; + } + + for(int k = 0, p = 0; k < 6; k++) + { + for(int n = 0; n < h.npart[k]; n++) + { + data->Id[p] = f->readInt32(); + p++; + } + } + f->endCheckpoint(); + } + catch (const InvalidUnformattedAccess& e) + { + cerr << "Invalid formatted while reading ID" << endl; + delete f; delete data; return 0; } - - for(int k = 0, p = 0; k < 6; k++) - { - for(int n = 0; n < h.npart[k]; n++) - { - data->Id[p] = f->readInt32(); - p++; - } - } - f->endCheckpoint(); } else { f->skip(2*4); for (int k = 0; k < 6; k++) diff --git a/src/loadRamses.cpp b/src/loadRamses.cpp index 01cd4c3..5306536 100644 --- a/src/loadRamses.cpp +++ b/src/loadRamses.cpp @@ -203,7 +203,7 @@ int readInfoFile(const char *basename, int outputId, InfoData& info) ostringstream ss_fname; ss_fname << basename << "/info_" << setfill('0') << setw(5) << outputId << ".txt"; - cout << "Opening info file " << ss_fname.str() << endl; +// cout << "Opening info file " << ss_fname.str() << endl; ifstream infile(ss_fname.str().c_str()); if (!infile) return 0; @@ -255,6 +255,178 @@ int readInfoFile(const char *basename, int outputId, InfoData& info) return 1; } +CosmoTool::SimuData *CosmoTool::loadRamsesSimu(const char *basename, int outputId, int cpuid, int flags) +{ + CosmoTool::SimuData *data = new CosmoTool::SimuData(); + + int id = 1; + uint32_t totPart = 0; + int nCpu = 0; + InfoData info; + + static const double CM_IN_MPC = 3.08e24; + + if (!readInfoFile(basename, outputId, info)) + return 0; + + double hubble = info.aexp*info.aexp/info.unit_t / (1e5/CM_IN_MPC); + double L0 = info.boxSize*info.unitLength*hubble/100/CM_IN_MPC/info.aexp; + double unit_vel = L0*hubble/info.aexp; + + while (1) + { + ostringstream ss_fname; + ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << id; + string fname = ss_fname.str(); + + try + { + UnformattedRead infile(fname); + + int ndim, nPar; + + infile.beginCheckpoint(); + nCpu = max(1,infile.readInt32()); + infile.endCheckpoint(); + + infile.beginCheckpoint(); + ndim = infile.readInt32(); + infile.endCheckpoint(); + + infile.beginCheckpoint(); + nPar = infile.readInt32(); + infile.endCheckpoint(); + + totPart += nPar; + id++; + } + catch (const NoSuchFileException& e) + { + break; + } + } + + + data->BoxSize = L0; + data->time = info.aexp; + data->NumPart = 0; + data->TotalNumPart = totPart; + + if (cpuid < 0) + cpuid = 1; + else cpuid++; + + uint32_t curPos = 0; + + ostringstream ss_fname; + ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << cpuid; + + string fname = ss_fname.str(); + + try + { + UnformattedRead infile(fname); + + int nCpu, ndim, nPar; + + infile.beginCheckpoint(); + nCpu = infile.readInt32(); + infile.endCheckpoint(); + + infile.beginCheckpoint(); + ndim = infile.readInt32(); + infile.endCheckpoint(); + + infile.beginCheckpoint(); + data->NumPart = nPar = infile.readInt32(); + infile.endCheckpoint(); + + if (flags & NEED_POSITION) + { + data->Pos[0] = new float[nPar]; + data->Pos[1] = new float[nPar]; + data->Pos[2] = new float[nPar]; + } + if (flags & NEED_VELOCITY) + { + data->Vel[0] = new float[nPar]; + data->Vel[1] = new float[nPar]; + data->Vel[2] = new float[nPar]; + } + if (flags & NEED_GADGET_ID) + { + data->Id = new int[nPar]; + } + + for (int k = 0; k < 3; k++) + { + infile.beginCheckpoint(); + if (flags & NEED_POSITION) + { + for (uint32_t i = 0; i < nPar; i++) + { + data->Pos[k][i] = infile.readReal32(); + data->Pos[k][i] *= data->BoxSize; + } + infile.endCheckpoint(); + } + else + infile.endCheckpoint(true); + } + + for (int k = 0; k < 3; k++) { + infile.beginCheckpoint(); + if (flags & NEED_VELOCITY) + { + for (uint32_t i = 0; i < nPar; i++) + { + data->Vel[k][i] = infile.readReal32(); + data->Vel[k][i] *= unit_vel; + } + infile.endCheckpoint(); + } + else + infile.endCheckpoint(true); + } + + float minMass = INFINITY; + infile.beginCheckpoint(); + for (uint32_t i = nPar; i > 0; i--) + { + float dummyF = infile.readReal32(); + if (dummyF < minMass) minMass = dummyF; + } + infile.endCheckpoint(); + + infile.beginCheckpoint(); + if (flags & NEED_GADGET_ID) + { + for (uint32_t i = 0; i < nPar; i++) + data->Id[i] = infile.readInt32(); + + infile.endCheckpoint(); + } + else + infile.endCheckpoint(true); + + curPos += nPar; + } + catch (const NoSuchFileException& e) + { + cerr << "No such file " << fname << endl; + delete data; + return 0; + } + + return data; +} + + + + + + + CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, int outputId, bool quiet) { PurePositionData *gd = (PurePositionData *)malloc(sizeof(PurePositionData)); diff --git a/src/loadRamses.hpp b/src/loadRamses.hpp index d725a70..c3efc84 100644 --- a/src/loadRamses.hpp +++ b/src/loadRamses.hpp @@ -2,6 +2,7 @@ #define _LOAD_RAMSES_HPP #include "load_data.hpp" +#include "loadSimu.hpp" namespace CosmoTool { @@ -10,6 +11,8 @@ namespace CosmoTool { PhaseSpaceData *loadRamsesPhase(const char *fname, int id, bool quiet = false); PhaseSpaceDataID *loadRamsesPhase1(const char *fname, int id, int cpuid, bool quiet = false); + + SimuData *loadRamsesSimu(const char *basename, int id, int cpuid, int flags); }; #endif diff --git a/src/loadSimu.hpp b/src/loadSimu.hpp index 965f266..79693f5 100644 --- a/src/loadSimu.hpp +++ b/src/loadSimu.hpp @@ -7,7 +7,7 @@ namespace CosmoTool static const int NEED_GADGET_ID = 1; static const int NEED_POSITION = 2; static const int NEED_VELOCITY = 4; - + static const int NEED_TYPE = 8; class SimuData { @@ -20,8 +20,9 @@ namespace CosmoTool int *Id; float *Pos[3]; float *Vel[3]; + int *type; public: - SimuData() : Id(0),NumPart(0) { Pos[0]=Pos[1]=Pos[2]=0; Vel[0]=Vel[1]=Vel[2]=0; } + SimuData() : Id(0),NumPart(0),type(0) { Pos[0]=Pos[1]=Pos[2]=0; Vel[0]=Vel[1]=Vel[2]=0; } ~SimuData() { for (int j = 0; j < 3; j++) @@ -31,6 +32,8 @@ namespace CosmoTool if (Vel[j]) delete[] Vel[j]; } + if (type) + delete[] type; if (Id) delete[] Id; } diff --git a/src/octTree.cpp b/src/octTree.cpp index a56e281..4ef929d 100644 --- a/src/octTree.cpp +++ b/src/octTree.cpp @@ -9,12 +9,27 @@ using namespace CosmoTool; //#define VERBOSE +static uint32_t mypow(uint32_t i, uint32_t p) +{ + if (p == 0) + return 1; + else if (p == 1) + return i; + + uint32_t k = p/2; + uint32_t j = mypow(i, k); + if (2*k==p) + return j*j; + else + return j*j*i; +} + OctTree::OctTree(const FCoordinates *particles, octPtr numParticles, uint32_t maxMeanTreeDepth, uint32_t maxAbsoluteDepth, uint32_t threshold) { cout << "MeanTree=" << maxMeanTreeDepth << endl; - numCells = pow(8, maxMeanTreeDepth); + numCells = mypow(8, maxMeanTreeDepth); assert(numCells < invalidOctCell); //#ifdef VERBOSE cerr << "Allocating " << numCells << " octtree cells" << endl;