### staging file

parent 20b2b64d
 include ../../example.mk CC=mpic++ LDIR = OBJ = main.o %.o: %.cpp $(CC) -O3 -c --std=c++11 -o$@ $<$(INCLUDE_PATH) expr: $(OBJ)$(CC) -o $@$^ $(CFLAGS)$(LIBS_PATH) $(LIBS) all: expr .PHONY: clean all clean: rm -f *.o *~ core expr  [pack] files = main.cpp Makefile File added  #include "Vector/vector_dist.hpp" #include "Operators/Vector/vector_dist_operators.hpp" /* * ### WIKI 1 ### * * ## Simple example to show how expression work with vector * * This example show how to use expressions to do complex calculation on particles * * ### WIKI END ### * */ constexpr int A = 0; constexpr int B = 1; constexpr int C = 2; constexpr int D = 3; // First we define the kernel function (an exponential in this case) struct exp_kernel { // variance of the exponential float sigma; // Constructor require to define the variance exp_kernel(float sigma) :sigma(sigma) {} // The kernel function accept the position p, the position q inline Point<3,double> value(const Point<3,float> & p, const Point<3,float> & q,Point<3,double> & Pp,Point<3,double> & Pq) { // calculate the distance between p and q float dist = norm(p-q); return Pq * exp(- dist * dist / sigma); } }; int main(int argc, char* argv[]) { // // ### WIKI 2 ### // // Here we Initialize the library, than we create a uniform random generator between 0 and 1 to to generate particles // randomly in the domain, we create a Box that define our domain, boundary conditions, and ghost // // initialize the library openfpm_init(&argc,&argv); // Here we define our domain a 2D box with intervals from 0 to 1.0 Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0}); // Here we define the boundary conditions of our problem size_t bc={PERIODIC,PERIODIC,PERIODIC}; // extended boundary around the domain, and the processor domain Ghost<3,float> g(0.01); // Delta t double dt = 0.01; // distributed vectors vector_dist<3,double, aggregate,Point<3,double>> > vd(4096,domain,bc,g); vector_dist<3,double, aggregate > vd2(4096,domain,bc,g); // Assign random position to the vector dist auto it = vd.getDomainIterator(); while (it.isNext()) { auto p = it.get(); vd.getPos(p) = (double)rand() / RAND_MAX; vd.getPos(p) = (double)rand() / RAND_MAX; vd.getPos(p) = (double)rand() / RAND_MAX; vd2.getPos(p) = (double)rand() / RAND_MAX; vd2.getPos(p) = (double)rand() / RAND_MAX; vd2.getPos(p) = (double)rand() / RAND_MAX; ++it; } // Redistribute the particles and synchronize the ghost vd.map(); vd.map(); // // ### WIKI ### // // Here we create alias for the properties of the vectors // // vA is an alias for the property A of the vector vd // vB is an alias for the property V of the vector vd // vC is ... auto vA = getV(vd); auto vB = getV(vd); auto vC = getV(vd); auto vD = getV(vd); auto vPOS = getV(vd); // same concept for the vector v2 auto v2A = getV<0>(vd); auto v2POS = getV(vd); // Assign 1 to the property A vA = 1; // Equal the property A to B vB = vA; // Assign to the property C and for each component 4.0 vC = 4; // Assign te position of the particle to the property D vD = vPOS; // // ### WIKI ### // // All these expression are applied point wise for each particles // // P.S. // // the * is a scalar product in case of vectors // simple multiplication in case of scalar // // // In vA we set the distance from the origin for each particle vA = norm(vPOS); // // For each particle p calculate the expression under // // NOTE sin(2.0 * vD) and exp(5.0 * vD) are both vector // // so this is a scalar product // | // V vA = vA + sin(2.0 * vD) * exp(1.2 * vD); // |_____________________________| // | // V // and this is a number // // // pmul indicate component-wise multiplication the same as .* in Matlab vC = pmul(vD,vD) * dt; // Normalization of the vector vD vD = vD / sqrt( vD * vD ); // we write the result on file vd.write("output"); // We can also apply the expression in a second moment like this Point<3,double> p0({0.5,0.5,0.5}); // we cannot use p0 directly we have to create an expression from it auto p0_e = getVExpr(p0); // As soon as the second vector have the some number of particle as v we can apply the expr1 to the v2 with v2D auto expr1 = 1.0/2.0/sqrt(M_PI)*exp(-(v2POS-p0_e)*(v2POS-p0_e)/2.0); // here is executed on all particles of v2 and the result assigned to the property A of v2 v2A = expr1; // // ### WIKI ### // // Each operator= produce a iteration across particles. It is possible to use the function assign // to execute multiple instructions in one cycle // // assign support an variable of istructions // assign(vA,1.0, // vA = 1 vB,expr1, // vB = 1.0/2.0/sqrt(M_PI)*exp(-(v2POS-p0_e)*(v2POS-p0_e)/2.0) vC,vD/norm(vD), // vC = vD/norm(vD) vD,2.0*vC); // vD = 2.0*vC // As soon as the vector v have the some number of particle as v2 we can apply the expr1 to v vA = expr1; // // ### WIKI ### // // we shown the simple usage of simple point-wise function like sin // and exp. Here we show the function applyKernel than encapsulate // the operation // // \sum_{q = Neighborhood p} Kernel(x_p,x_q,Up,Uq) * expression // // where x_p is the position of the particle p // x_q is the position of the particle q // U_p is the value of the property carried by the particle p // U_q is the value of the property carried by the particle q // // exp_kernel ker(0.5); auto cl = vd.getCellList(0.1); // We are going to do some calculation that require ghost, so sync it vd.ghost_get<3>(); // Here we create the // A renormalizaion of the vector vD is calculated on fly // // and than For each particle p // // \sum_{q = Neighborhood p} Ker(x_p,x_q,D_p,D_q) * \frac{D}{norm(D)} // // // P.S. // // Cerefull here ApplyKernel is a special function if it act on property D we cannot write on property D // ( vD = ... is an error and produce unpredictable result ) // vC = applyKernel_in( vD / norm(vD) ,vd,cl,ker) + vD; // ok, because does not use applyKernel vD = vD / norm(vD); // // ### WIKI 9 ### // // Output the particle position for each processor // vd.deleteGhost(); vd.write("output2"); // // ### WIKI 10 ### // // Deinitialize the library // openfpm_finalize(); } This diff is collapsed. footer.html 0 → 100644  header.html 0 → 100644 $projectname: $title$title $treeview$search $mathjax$extrastylesheet
$projectname$projectnumber
$projectbrief$projectbrief
$searchbox  ... ... @@ -329,14 +329,8 @@ else fi ### Create example.mk # Where openfpm is going to be installed install_base=$(cat install_dir) echo "INCLUDE_PATH=-I. -I$install_base/openfpm_numerics/include -I$install_base/openfpm_pdata/include/config -I$install_base/openfpm_pdata/include -I$install_base/openfpm_data/include -I$install_base/openfpm_vcluster/include -I$install_base/openfpm_io/include -I$install_base/openfpm_devices/include -I$i_dir/METIS/include -I$i_dir/PARMETIS/include -I$i_dir/BOOST/include -I$i_dir/HDF5/include$lin_alg_inc" > example.mk echo "LIBS_PATH= -L$install_base/openfpm_devices/lib -L$install_base/openfpm_pdata/lib -L$install_base/openfpm_vcluster/lib -L$i_dir/METIS/lib -L$i_dir/PARMETIS/lib -L$i_dir/BOOST/lib -L$i_dir/HDF5/lib$lin_alg_dir" >> example.mk echo "LIBS=-lvcluster -lofpm_pdata -lofpmmemory -lparmetis -lmetis -lboost_iostreams -lhdf5 $lin_alg_lib" >> example.mk echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lparmetis -lmetis -lboost_iostreams -lhdf5$lin_alg_lib" >> example.mk cp example.mk src/example.mk cp example.mk example/example.mk make clean make ... ... @@ -364,6 +358,10 @@ echo "" echo -e "\033[1;34;5m ---------- Mandatory packages --------- \033[0m" echo "" example_library_path="" example_library="" example_include_path="" if [ -d "$i_dir/MPI" ]; then installation_report="$installation_report \033[92;1mMPI\033[0m Installed: \033[1m $i_dir/MPI \033[0m\n" bash_path="$bash_path:$i_dir/MPI/bin" ... ... @@ -375,16 +373,25 @@ fi if [ -d "$i_dir/METIS" ]; then installation_report="$installation_report \033[92;1mMETIS\033[0m Installed: \033[1m$i_dir/METIS \033[0m\n" bash_library="$bash_library:$i_dir/METIS/lib" example_library_path="$example_library_path -L$i_dir/METIS/lib" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/METIS/include" fi if [ -d "$i_dir/PARMETIS" ]; then installation_report="$installation_report \033[92;1mPARMETIS\033[0m Installed: \033[1m$i_dir/PARMETIS \033[0m\n" bash_library="$bash_library:$i_dir/PARMETIS/lib" example_library_path="$example_library_path -L$i_dir/PARMETIS/lib" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/PARMETIS/include" fi if [ -d "$i_dir/BOOST" ]; then installation_report="$installation_report \033[92;1mBOOST\033[0m Installed: \033[1m$i_dir/BOOST \033[0m\n" bash_library="$bash_library:$i_dir/BOOST/lib" example_library_path="$example_library_path -L$i_dir/BOOST/lib" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/BOOST/include" elif [$BOOST_System_prv -eq 1 ]; then installation_report="$installation_report \033[92;1mBOOST\033[0m Installed: \033[1m System installation \033[0m\n" fi ... ... @@ -392,6 +399,9 @@ fi if [ -d "$i_dir/HDF5" ]; then installation_report="$installation_report \033[92;1mHDF5\033[0m Installed: \033[1m$i_dir/HDF5 \033[0m\n" bash_library="$bash_library:$i_dir/HDF5/lib" example_library_path="$example_library_path -L$i_dir/HDF5/lib" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/HDF5/include" fi echo -e "$installation_report" ... ... @@ -405,12 +415,18 @@ installation_report="" if [ -d "$i_dir/PETSC" ]; then installation_report="$installation_report \033[92;1mPETSC\033[0m Installed: \033[1m $i_dir/PETSC \033[0m\n" bash_library="$bash_library:$i_dir/PETSC/lib" example_library_path="$example_library_path -L$i_dir/PETSC/lib" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/PETSC/include" else installation_report="$installation_report \033[91;1mPETSC\033[0m Installed: \033[1m NO \033[0m\n" fi if [ -d "$i_dir/EIGEN" ]; then installation_report="$installation_report \033[92;1mEIGEN\033[0m Installed: \033[1m$i_dir/EIGEN \033[0m\n" example_library_path="$example_library_path" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/EIGEN/include" fi echo -e "$installation_report" ... ... @@ -422,6 +438,9 @@ installation_report="" if [ -d "$i_dir/TRILINOS" ]; then installation_report="$installation_report \033[92;1mTRILINOS\033[0m Installed: \033[1m$i_dir/TRILINOS \033[0m\n" bash_library="$bash_library:$i_dir/TRILINOS/lib" example_library_path="$example_library_path" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/TRILINOS/include" else installation_report="$installation_report \033[91;1mTRILINOS\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -429,6 +448,8 @@ fi if [ -d "$i_dir/OPENBLAS" ]; then installation_report="$installation_report \033[92;1mOPENBLAS\033[0m Installed: \033[1m$i_dir/OPENBLAS \033[0m\n" bash_library="$bash_library:$i_dir/OPENBLAS/lib" example_library_path="$example_library_path" example_library="$example_library" else installation_report="$installation_report \033[91;1mOPENBLAS\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -436,6 +457,9 @@ fi if [ -d "$i_dir/SUITESPARSE" ]; then installation_report="$installation_report \033[92;1mSUITESPARSE\033[0m Installed: \033[1m$i_dir/SUITESPARSE \033[0m\n" bash_library="$bash_library:$i_dir/SUITESPARSE/lib" example_library_path="$example_library_path -L$i_dir/SUITESPARSE/lib" example_library="$example_library" example_include_path="$example_include_path -I$i_dir/SUITESPARSE/include" else installation_report="$installation_report \033[91;1mSUITESPARSE\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -443,6 +467,8 @@ fi if [ -d "$i_dir/SCALAPACK" ]; then installation_report="$installation_report \033[92;1mSCALAPACK\033[0m Installed: \033[1m $i_dir/SCALAPACK \033[0m\n" bash_library="$bash_library:$i_dir/SCALAPACK/lib" example_library_path="$example_library_path" example_library="$example_library" else installation_report="$installation_report \033[91;1mSCALAPACK\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -450,6 +476,8 @@ fi if [ -d "$i_dir/MUMPS" ]; then installation_report="$installation_report \033[92;1mMUMPS\033[0m Installed: \033[1m $i_dir/MUMPS \033[0m\n" bash_library="$bash_library:$i_dir/MUMPS/lib" example_library_path="$example_library_path" example_library="$example_library" else installation_report="$installation_report \033[91;1mMUMPS\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -457,6 +485,8 @@ fi if [ -d "$i_dir/SUPERLU_DIST" ]; then installation_report="$installation_report \033[92;1mSUPERLU_DIST\033[0m Installed: \033[1m $i_dir/SUPERLU_DIST \033[0m\n" bash_library="$bash_library:$i_dir/SUPERLU_DIST/lib" example_library_path="$example_library_path" example_library="$example_library" else installation_report="$installation_report \033[91;1mSUPERLU_DIST\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -464,6 +494,8 @@ fi if [ -d "$i_dir/HYPRE" ]; then installation_report="$installation_report \033[92;1mHYPRE\033[0m Installed: \033[1m $i_dir/HYPRE \033[0m\n" bash_library="$bash_library:$i_dir/HYPRE/lib" example_library_path="$example_library_path" example_library="$example_library" else installation_report="$installation_report \033[91;1mHYPRE\033[0m Installed: \033[1m NO \033[0m\n" fi ... ... @@ -476,6 +508,15 @@ bash_library="$bash_library\"" echo "$bash_path" > $HOME/openfpm_vars echo "$bash_library" >> $HOME/openfpm_vars ### Create example.mk echo "INCLUDE_PATH=-I. -I$install_base/openfpm_numerics/include -I$install_base/openfpm_pdata/include/config -I$install_base/openfpm_pdata/include -I$install_base/openfpm_data/include -I$install_base/openfpm_vcluster/include -I$install_base/openfpm_io/include -I$install_base/openfpm_devices/include $example_include_path$lin_alg_inc" > example.mk echo "LIBS_PATH= -L$install_base/openfpm_devices/lib -L$install_base/openfpm_pdata/lib -L$install_base/openfpm_vcluster/lib$example_library_path $lin_alg_dir" >> example.mk echo "LIBS=-lvcluster -lofpm_pdata -lofpmmemory -lparmetis -lmetis -lboost_iostreams -lhdf5$lin_alg_lib" >> example.mk echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lparmetis -lmetis -lboost_iostreams -lhdf5 $lin_alg_lib" >> example.mk cp example.mk src/example.mk cp example.mk example/example.mk echo -e "$installation_report" echo "" echo "" ... ...
ofpdoxygen.css 0 → 100644
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!