Commit e6468840 authored by jcl's avatar jcl

plug projects into unsio

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@97 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 9af1ffe1
# ============================================================================
# Copyright Jean-Charles LAMBERT - 2010
# e-mail: Jean-Charles.Lambert@oamp.fr
# address: Dynamique des galaxies
# Laboratoire d'Astrophysique de Marseille
# Pole de l'Etoile, site de Chateau-Gombert
# 38, rue Frederic Joliot-Curie
# 13388 Marseille cedex 13 France
# CNRS U.M.R 6110
# ============================================================================
# CMakeListst.txt file for UNS library
# ============================================================================
cmake_minimum_required(VERSION 2.6)
# project name
project (uns_projects)
# set CMAKE Module PATH (NEMO)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_BINARY_DIR})
MESSAGE( STATUS "CMAKE_MODULE_PATH=" ${CMAKE_MODULE_PATH} )
# require NEMO
FIND_PACKAGE(NEMO REQUIRED)
# Sqlite3
FIND_PACKAGE(SQLITE3)
# detect MacOS
SET(OSX FALSE)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(OSX TRUE)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# require boost
find_package( Boost 1.36.0)
set(LIBBOOST boost_thread-mt.a boost_system-mt.a)
set(DNOBOOST "")
set(Boost_FOUND FALSE)
if(NOT Boost_FOUND)
MESSAGE (STATUS " Boost not found, uns_2dplot will run slowly.....")
set(DNOBOOST "-DNOBOOST")
set(LIBBOOST "")
endif(NOT Boost_FOUND)
# Some necessary variable
set(DEHNEN $ENV{NEMO}/usr/dehnen)
set(NEMOLIB $ENV{NEMOLIB})
#FIND_PACKAGE(NEMO REQUIRED)
MESSAGE( STATUS "NEMOLIB : " ${NEMOLIB} )
# contains the full path to the top level directory of your build tree
MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )
#MESSAGE ( STATUS "Boost_LIBRARY_DIRS : " ${Boost_LIBRARY_DIRS})
# contains the full path to the root of your project source directory,
# i.e. to the nearest directory where CMakeLists.txt contains the PROJECT() command
MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )
# Find all the sources for the utils LIB
FILE(GLOB LIBUTILS ../lib/utils/*.cc)
# create the library "JCLutils"
add_library (JCLutils SHARED ${LIBUTILS})
if(OSX)
set_target_properties(JCLutils PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace")
endif(OSX)
# Find all the sources for the projects LIB
FILE(GLOB LIBPROJECTS ../lib/projects/*.cc)
# create the library "JCLutils"
add_library (JCLprojects SHARED ${LIBPROJECTS})
if(OSX)
set_target_properties(JCLprojects PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace")
endif(OSX)
# Destination path for the lib
SET(LIBRARY_OUTPUT_PATH ../lib)
# compilation options
add_definitions( -DNO_CUDA -O3 -DfalcON_NEMO -DfalcON_SINGLE -funroll-loops -Wall ${DNOBOOST})
# Executbale output path
set(EXECUTABLE_OUTPUT_PATH ../bin)
MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )
# Make sure the compiler can find include files from our Hello library.
include_directories (../lib/utils ../lib/projects ${DEHNEN}/falcON/inc ${DEHNEN}/falcON/utils/inc $ENV{NEMOINC} ${NEMOLIB} $ENV{NEMOINC}/uns)
# Make sure the linker can find the Hello library once it is built.
link_directories (${NEMOLIB} ${DEHNEN}/falcON/lib ${DEHNEN}/utils/lib $ENV{PGPLOT_DIR} ${G2C_DIR} ${PROJECT_BINARY_DIR}/../lib /usr/lib64 /usr/X11/lib ${FC_GFORT_PATH} ${FC_G77_PATH}
)
# ----------------------------------------------------------
# Make sure the compiler can find include files from our Hello library.
#include_directories (${UNS_SOURCE_DIR}/src $ENV{NEMOINC} ${NEMOLIB})
# Find all LIB's sources files
FILE(GLOB execpp_sources ../src/*.cc ../src/*.c)
# build cpp executables according to the source
FOREACH(exe_cpp ${execpp_sources})
get_filename_component(exe ${exe_cpp} NAME_WE)
MESSAGE( STATUS "New executable ==> " ${exe})
add_executable (${exe} ${exe_cpp})
# Link the executable to the Hello library.
# target_link_libraries (${exe} JCLutils JCLprojects cpgplot pgplot X11 g2c unsio nemo sqlite3 ${Boost_LIBRARIES} boost_thread-mt.a boost_system-mt.a)
target_link_libraries (${exe} JCLutils JCLprojects cpgplot pgplot.a ${FC_GFORT_LIB} ${FC_G77_LIB} X11 unsio WDutils falcON nemo ${SQLITE3_LIB} gomp ${LIBBOOST} pthread dl)
ENDFOREACH(exe_cpp ${execpp_sources})
# ----------------------------------------------------------
# install target
set (CMAKE_INSTALL_PREFIX $ENV{NEMO})
IF (OSX) # Mac OSX
SET(SOEXT "dylib")
ELSE (OSX) # Linux
SET(SOEXT "so")
ENDIF(OSX)
#
# install bin targets
FOREACH(exe_cpp ${execpp_sources})
get_filename_component(exe ${exe_cpp} NAME_WE)
INSTALL(PROGRAMS ${PROJECT_BINARY_DIR}/../bin/${exe} DESTINATION bin)
ENDFOREACH(exe_cpp ${execpp_sources})
INSTALL(FILES ${PROJECT_BINARY_DIR}/../lib/libJCLutils.${SOEXT} DESTINATION lib)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../lib/libJCLprojects.${SOEXT} DESTINATION lib)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../man/uns_2dplot.1 DESTINATION man/man1)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../man/uns_stack.1 DESTINATION man/man1)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../man/uns2uns.1 DESTINATION man/man1)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../man/uns_projects.1 DESTINATION man/man1)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../lib/utils/cfalcon.h DESTINATION inc/uns)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../lib/utils/csnaptools.h DESTINATION inc/uns)
INSTALL(FILES ${PROJECT_BINARY_DIR}/../lib/utils/ctimer.h DESTINATION inc/uns)
#
SET(NEMO_INSTALLED FALSE)
FILE(GLOB GLOB_TEMP_VAR $ENV{NEMO})
IF(GLOB_TEMP_VAR)
SET(NEMO_INSTALLED TRUE)
ENDIF(GLOB_TEMP_VAR)
if (NOT NEMO_INSTALLED)
MESSAGE(SEND_ERROR "NEMO environement not loaded, cannot continue....")
endif (NOT NEMO_INSTALLED)
SET(NEMO_INSTALLED FALSE)
FILE(GLOB GLOB_TEMP_VAR $ENV{NEMO})
IF(GLOB_TEMP_VAR)
SET(NEMO_INSTALLED TRUE)
# Detect fortran compiler from ${NEMOLIB}/makedefs
# files (variable FC = )
FILE(READ $ENV{NEMOLIB}/makedefs MAKEDEFS)
STRING(REGEX MATCH "FC = gfortran" GFORTRAN_IS_SET ${MAKEDEFS})
IF ("FC = gfortran" STREQUAL "${GFORTRAN_IS_SET}")
MESSAGE("GFortran compiler Detected......")
SET (FORT_COMP gfortran)
ELSE("FC = gfortran" STREQUAL "${GFORTRAN_IS_SET}")
# g77 stuffs
MESSAGE("Assuming G77 compiler")
SET (FORT_COMP g77)
ENDIF ("FC = gfortran" STREQUAL "${GFORTRAN_IS_SET}")
# gfortran stuffs
SET (FC_GFORT_LIB "")
SET (FC_GFORT_PATH "")
set (GFORTPATH "")
execute_process(COMMAND gfortran -print-file-name=libgfortran.a
OUTPUT_VARIABLE GFORTPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (NOT ${GFORTPATH} STREQUAL "")
MESSAGE("GFORTRAN compiler exist, adding libgfortran......")
execute_process(COMMAND dirname ${GFORTPATH}
OUTPUT_VARIABLE FC_GFORT_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
SET (FC_GFORT_LIB gfortran)
ENDIF(NOT ${GFORTPATH} STREQUAL "")
# g77 stuffs
SET (FC_G77_LIB "")
SET (FC_G77_PATH "")
set (G2CFPATH "")
execute_process(COMMAND g77 -print-file-name=libg2c.a
OUTPUT_VARIABLE G2CFPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (NOT ${G2CFPATH} STREQUAL "")
MESSAGE("G77 compiler exist, adding libg2c......")
execute_process(COMMAND dirname ${G2CFPATH}
OUTPUT_VARIABLE FC_G77_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
SET (FC_G77_LIB g2c)
ENDIF(NOT ${G2CFPATH} STREQUAL "")
ENDIF(GLOB_TEMP_VAR)
if (NOT NEMO_INSTALLED)
MESSAGE(STATUS "NEMO environement not loaded.... using nemo_light")
endif (NOT NEMO_INSTALLED)
This diff is collapsed.
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2009-2011
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 6110
// ============================================================================
/*
@author Jean-Charles Lambert <Jean-Charles.Lambert@oamp.fr>
*/
#ifndef C2DPLOT_H
#define C2DPLOT_H
#include <string>
#include <vector>
#include <iostream>
#ifndef NOBOOST
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#endif
#include "cgaussian.h"
#define NTHREAD_MAX 256
#ifndef NO_CUDA
#define NB_BLOCK 2
#endif
namespace uns_proj {
typedef struct {
int devid;
int nblock, offset;
} t_cuda_grid;
template <class T> class C2dplot {
public:
C2dplot(const int,const int,const int, const int, const T);
void compute(std::string pic, const int _no_frame,const int _nbody, T * _pos ,
float _range[3][2], std::string _title,
std::string _sel_comp, std::string _filename, float _time,
bool _xy, bool _xz, bool _zy, bool _sview);
private:
int nthreads, dimx, dimy, pixel;
jclut::CGaussian<float> * gaussian;
T g;
float * tab[NTHREAD_MAX];
std::vector <int> indexes;
// drawImage
void drawImage(const bool disp,const int xaxis, const int yaxis, const int nbview, int &showtext);
// computeImage
void computeImage(const int xaxis, const int yaxis);
// buildFrameName
std::string buildFrameName(std::string label,const int idx);
// display text
void displayText(bool sview);
void findIndexes(const int xaxis, const int yaxis);
void displayIndexes() {
for (unsigned int i=0; i<indexes.size(); i++) {
std::cerr << indexes[i] << "\n";
}
}
// Parallel tasks
void startWorkers(const int nbody, T * data, const int xaxis, const int yaxis,float& zmin,float& zmax);
void worker(const int ithread, const int offset, const int nbody, T * data, const int xaxis, const int yaxis);
#ifndef NOBOOST
std::vector<boost::shared_ptr<boost::thread> > v_threads;
boost::mutex io_mutex;
#endif
float xmin,xmax,ymin,ymax;
std::string dev, title, sel_comp, filename;
int no_frame, nbody;
float time,range[3][2];
T * pos;
bool xy, xz, zy, sview;
#ifndef NO_CUDA
// CUDA stuffs
int GPU_N;
t_cuda_grid * device_data;
float
* cuda_pos; // particles's positions
int
c_nbody; // #cuda bodies particles
void initCuda();
void startCuda(const int nbody, T * data, const int xaxis, const int yaxis,float& zmin,float& zmax);
void workerCudaThread(const int id, T * data, const int xaxis, const int yaxis);
#endif
};
}
#endif
//
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2011
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 6110
// ============================================================================
#include <iostream>
#include <cmath>
#include <sstream>
#include "cbar.h"
#include "uns.h"
#include "csnaptools.h"
using namespace uns_proj;
using namespace std;
#define PI 3.141592653589793238462643
// ----------------------------------------------------------------------------
// contructor
CBar::CBar(const int _nbody, float * _pos, float * _vel, float * _mass, float *_rho, float *_hsml)
{
// link arguments
nbody = _nbody;
pos = _pos;
vel = _vel;
mass= _mass;
density = NULL;
rho = _rho;
hsml=_hsml;
// sort by rho
sortRho();
}
// ----------------------------------------------------------------------------
// contructor
CBar::~CBar()
{
if (density) delete density;
}
// ----------------------------------------------------------------------------
// computeAngle();
// Based on anglebar_impr.F
// with new method using density instead of mass
float CBar::computeAngle(const float dmin, const float dmax, const bool mvcod)
{
// shift to COD
double cod[6]={0.,0.,0.,0.,0.,0.};
if (mvcod)
CSnaptools::moveToCod<float>(nbody,&pos[0],&vel[0],&mass[0],rho,cod,false);
float alpha=0.0;
float beta =0.0;
float minrho=log(rho[vec_rho.at(0).index]);
float maxrho=log(rho[vec_rho.at(nbody-1).index]);
float binf=minrho+dmin*(maxrho-minrho);
float bsup=minrho+dmax*(maxrho-minrho);
std::cerr << "binf/bsup :"<< binf<<"/"<<bsup<<"\n";
int cpt=0;
//for (int i=dmin*nbody; i<dmax*nbody; i++) {
for (int i=0; i<nbody;i++) {
int ii= vec_rho.at(i).index;
float rhoii = log(rho[ii]);
if ((rhoii)>=binf && (rhoii)<=bsup ) {
cpt++;
float x = pos[ii*3+0]-cod[0];
float y = pos[ii*3+1]-cod[1];
float x2 = x*x;
float y2 = y*y;
float r2 = x2+y2;
float cos2th = (x2 - y2) / r2;
float sin2th = 2. * x * y / r2;
#if 1
alpha += rho[ii]*sin2th;
beta += rho[ii]*cos2th;
#else
alpha += mass[ii]*sin2th;
beta += mass[ii]*cos2th;
#endif
}
}
std::cerr << "Found ["<<cpt<<"] particles into the range.\n";
assert(cpt>0);
float bar_angle = 0.5 * atan2(alpha,beta);
return bar_angle;
}
// ----------------------------------------------------------------------------
// computeAngle();
// Based on anglebar_impr.F
// with new method using density instead of mass
// select max #particles per density shells
// guess rotation angle from selected particles
float CBar::computeAngle(const bool mvcod)
{
float minrho=log(rho[vec_rho.at(0).index]);
float maxrho=log(rho[vec_rho.at(nbody-1).index]);
// reset array
for (int i=0; i<100; i++) {
data_histo[i] = 0;
}
// compute #particles per density shell
for (int i=0; i<nbody;i++) {
int ii= vec_rho.at(i).index;
int index=((log(rho[ii])-minrho)*99.)/(maxrho-minrho);
//std::cerr << "CBar::computeAngle index="<<index<<"\n";
assert(index<100);
data_histo[index]++;
}
// find max shell
int maxshell=data_histo[0];
int ishell=0;
for (int i=1;i<100;i++) {
if (data_histo[i]>maxshell) {
maxshell = data_histo[i];
ishell=i;
}
}
float dmax=std::max(ishell+5,ishell);
float dmin=std::max(0.,(ishell-20.));
std::cerr << "CBar::computeAngle dmin="<<dmin<<"/ dmax="<<dmax<<"\n";
return computeAngle(dmin/100.,dmax/100.,mvcod);
}
// ----------------------------------------------------------------------------
// rotateOnX
void CBar::rotateOnX(const float bar_angle)
{
float theta = -bar_angle;
rotate(theta);
}
// ----------------------------------------------------------------------------
// rotateOnY
void CBar::rotateOnY(const float bar_angle)
{
float theta = 0.5*M_PI-bar_angle;
rotate(theta);
}
// ----------------------------------------------------------------------------
// rotate
void CBar::rotate(const float theta)
{
for (int i=0; i<nbody; i++) {
float rx = pos[i*3+0] * cos(theta) - pos[i*3+1] * sin(theta);
float ry = pos[i*3+0] * sin(theta) + pos[i*3+1] * cos(theta);
pos[i*3+0] = rx;
pos[i*3+1] = ry;
}
if (vel) { // velocities exist
for (int i=0; i<nbody; i++) {
float rx = vel[i*3+0] * cos(theta) - vel[i*3+1] * sin(theta);
float ry = vel[i*3+0] * sin(theta) + vel[i*3+1] * cos(theta);
vel[i*3+0] = rx;
vel[i*3+1] = ry;
}
}
}
// ----------------------------------------------------------------------------
// save
void CBar::save(std::string out, const float timu, const bool mvcod)
{
// shift to COD
double cod[6]={0.,0.,0.,0.,0.,0.};
if (mvcod)
CSnaptools::moveToCod<float>(nbody,&pos[0],&vel[0],&mass[0],rho,cod,true);
// save data
uns::CunsOut * unsout = new uns::CunsOut(out,"nemo",false);
unsout->snapshot->setData("time",timu);
unsout->snapshot->setData("mass",nbody,mass,false);
unsout->snapshot->setData("pos" ,nbody,pos ,false);
unsout->snapshot->setData("vel" ,nbody,vel ,false);
unsout->snapshot->setData("rho" ,nbody,rho ,false);
unsout->snapshot->setData("hsml",nbody,hsml,false);
unsout->snapshot->save();
delete unsout;
}
// ----------------------------------------------------------------------------
// saveAllRho
void CBar::saveAllRho(std::string out)
{
int cpt=0;
for (int i=0;i<99;i++) {
int start=nbody*(float)(i )/100.;
int end =nbody*(float)(i+1)/100.;
end = std::min(end,nbody);
int n=end-start;
if (n>0) {
float * p = new float[n*3]; // pos
float * r = new float[n]; // rho
float * h = new float[n]; // hsml
int ii=0;
for (int i=start; i<start+n; i++) {
//for (int i=0; i<end; i++) {
int indx = vec_rho.at(i).index;
p[ii*3+0] = pos[indx*3+0];
p[ii*3+1] = pos[indx*3+1];
p[ii*3+2] = pos[indx*3+2];
r[ii] = rho[indx];
h[ii] = hsml[indx];
ii++;
}
assert(ii==n);
stringstream ss;
ss << out << "." << setw(5) << setfill('0') << cpt++;
uns::CunsOut * unsout = new uns::CunsOut(ss.str(),"nemo",false);
unsout->snapshot->setData("pos" ,n,p,false);
unsout->snapshot->setData("rho" ,n,r,false);
unsout->snapshot->setData("hsml",n,h,false);
unsout->snapshot->save();
delete unsout;
delete [] p;
delete [] r;
delete [] h;
}
}
}
// ----------------------------------------------------------------------------
// sortRho();
void CBar::sortRho()
{
if (!rho) {
std::cerr << "Density NULL during instantiation, we gonna compute density!!\n";
// Instantiate a density object
density = new CDensity(nbody,&pos[0],&mass[0]);
density->compute(0,32,1,8); // estimate density
rho = density->getRho();
hsml= density->getHsml();
}
// put particles into a vector
vec_rho.clear();
vec_rho.reserve(nbody);
for (int i=0;i<nbody;i++) {
CVecRho p(this,i);
vec_rho.push_back(p);
}
// Descending sort particles according to their densities
std::sort(vec_rho.begin(),vec_rho.end(),CVecRho::sortRho);
}
// ----------------------------------------------------------------------------
// VecRho
bool CVecRho::sortRho(const CVecRho& a, const CVecRho& b)
{
return a.bar->getRho()[a.index] < b.bar->getRho()[b.index];
}
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2011
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 6110
// ============================================================================
/*
@author Jean-Charles Lambert <Jean-Charles.Lambert@oamp.fr>
*/
#include "cfalcon.h"
#include <vector>
#ifndef CBAR_H
#define CBAR_H
using namespace jclut;
namespace uns_proj {
class CBar;
//------------------------------------------------------------------------------
// CPartVec
// class to store rho, index and id of particles
class CVecRho {
public:
CVecRho(CBar * _bar, int _index) {
index = _index;
bar = _bar;
}
static bool sortRho(const CVecRho& a, const CVecRho& b);
static bool sortId (const CVecRho& a, const CVecRho& b);
int index;
CBar * bar;
};
class CBar {
public:
CBar(const int _nbody, float * _pos, float * _vel, float * mass,
float * _rho, float *_hsml);
~CBar();
float * getRho() { return rho;}
float computeAngle(const float dmin, const float dmax, const bool mvcod=false);
float computeAngle(const bool mvcod=false);
void rotateOnX(const float);
void rotateOnY(const float);
void saveAllRho(std::string out);
void save(std::string out, const float timu,const bool mvcod);
private:
int nbody;
float * pos, * vel, *mass, *rho, *hsml;
CDensity * density;
int data_histo[100]; // store #particles per percentage
std::vector <CVecRho> vec_rho;
void sortRho();
void rotate(const float angle);
}; // end of class
} // namespace
#endif // CBAR_H
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2011
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 6110
// ============================================================================
#include <cpgplot.h>
#include <iostream>
#include <cmath>
#include "cfitsellipse.h"
#include "csnaptools.h"
#include "uns.h"
#include "cgaussian.h"
using namespace uns_proj;
using namespace jclut;
using namespace std;
// ----------------------------------------------------------------------------
// contructor
CFitsEllipse::CFitsEllipse(const int _xaxis, const int _yaxis, const int nm, const float _tmax)
{
tmax = _tmax;
nmesh = nm;
xaxis = _xaxis;
yaxis = _yaxis;
// create grid
grid = new float[nmesh*nmesh];
}
// ----------------------------------------------------------------------------
// destructor