OpenFPM  5.2.0
Project that contain the implementation of distributed structures
Bunny.cpp
1 // ------------------------------------------------------------------------------------------
2 // Copyright (C) 2021 ---- absingh
3 //
4 // This file is part of the Surface DCPSE Paper.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // ------------------------------------------------------------------------------------------
19 
20 #include "Vector/vector_dist_subset.hpp"
21 #include "DCPSE/DCPSE_op/DCPSE_surface_op.hpp"
22 #include "DCPSE/DCPSE_op/DCPSE_Solver.hpp"
23 #include "util/SphericalHarmonics.hpp"
24 #include <util/PathsAndFiles.hpp>
25 
26 std::string p_output;
27 
28 constexpr int DF=0;
29 constexpr int F=1;
30 constexpr int ANADF=2;
31 constexpr int ERR=3;
32 constexpr int NORMAL=4;
33 constexpr int PCOORD=5;
34 
36 openfpm::vector<std::string> propNames{{"Df","f","AnaDf","error","Normal","PCOORD"}};
38 
39 int main(int argc, char * argv[]) {
40  openfpm_init(&argc,&argv);
41  auto & v_cl = create_vcluster();
42  timer tt;
43  tt.start();
44  double grid_spacing_surf;
45  double rCut;
46  double EIGENVAL;
47 
48  // Get command line arguments
49  if (argc < 3) {
50  std::cout << "Error: The executable requires the following arguments: number_grid_points" << std::endl;
51  return 0;
52  }
53  else {
54  //n = std::stoi(argv[1]);
55  //spL=std::stof(argv[2]);
56  grid_spacing_surf=std::stof(argv[1]);
57  EIGENVAL=std::stof(argv[2]);
58  //rCut=std::stof(argv[4]);
59  }
60 
61  // Files and directories
62  std::string cwd{boost::filesystem::current_path().string()};
63  std::string output_dir{cwd + "/output_Bunny"};
65  p_output = output_dir + "/particles";
66  double boxP1{-1.5}, boxP2{1.5};
67  double boxSize{boxP2 - boxP1};
68  rCut=2.5 * grid_spacing_surf;
69 
70  Box<3,double> domain{{boxP1,boxP1,boxP1},{boxP2,boxP2,boxP2}};
71  size_t bc[3] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
72  Ghost<3,double> ghost{rCut + grid_spacing_surf/8.0};
73 
74  // particles
75  vector_type particles{0,domain,bc,ghost};
76  particles.setPropNames(propNames);
77  double Nx,Ny,Nz,Px,Py,Pz;
78  std::ifstream PCfile;
79  PCfile.open("data.csv");
80  if(v_cl.rank()==0){
81  int pctr=0;
82  while ( PCfile >> Nx >> Ny >> Nz >> Px >> Py >> Pz )
83  {
84  particles.add();
85  particles.getLastPos()[0]=Px;
86  particles.getLastPos()[1]=Py;
87  particles.getLastPos()[2]=Pz;
88  particles.getLastProp<NORMAL>()[0]=Nx;
89  particles.getLastProp<NORMAL>()[1]=Ny;
90  particles.getLastProp<NORMAL>()[2]=Nz;
91  ++pctr;
92  }
93  particles.getLastSubset(1);
94  std::cout << "n: " << pctr << " - rCut: " << rCut << "nSpacing" << grid_spacing_surf<<std::endl;
95  }
96 
97  particles.map();
100 
102  vector_dist_subset<3,double,prop> particles_boundary(particles,1);
103  auto &bulkIds=particles_bulk.getIds();
104  auto &bdrIds=particles_boundary.getIds();
105 
106  auto DErr=getV<ERR>(particles);
107  auto Af=getV<ANADF>(particles);
108  auto Df=getV<DF>(particles);
109  auto f=getV<F>(particles);
110  auto N=getV<NORMAL>(particles);
111 
112  auto verletList = particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
113  SurfaceDerivative_x<NORMAL,decltype(verletList)> Sdx{particles,verletList,2,rCut,grid_spacing_surf,rCut/grid_spacing_surf};
114  SurfaceDerivative_y<NORMAL,decltype(verletList)> Sdy{particles,verletList,2,rCut,grid_spacing_surf,rCut/grid_spacing_surf};
115  SurfaceDerivative_z<NORMAL,decltype(verletList)> Sdz{particles,verletList,2,rCut,grid_spacing_surf,rCut/grid_spacing_surf};
116 
117  SurfaceDerivative_xx<NORMAL,decltype(verletList)> Sdxx{particles,verletList,2,rCut,grid_spacing_surf,rCut/grid_spacing_surf};
118  SurfaceDerivative_yy<NORMAL,decltype(verletList)> Sdyy{particles,verletList,2,rCut,grid_spacing_surf,rCut/grid_spacing_surf};
119  SurfaceDerivative_zz<NORMAL,decltype(verletList)> Sdzz{particles,verletList,2,rCut,grid_spacing_surf,rCut/grid_spacing_surf};
120 
121  DErr=-0.5*(Sdx(N[0])+Sdy(N[1])+Sdz(N[2]));
123  particles.write_frame(p_output,0,BINARY);
124 
125 
126  DCPSE_scheme<equations3d1, decltype(particles)> Solver(particles);
127  auto Eig = Sdxx(f)+Sdyy(f)+Sdzz(f)-EIGENVAL*f;
128  Solver.impose(Eig, bulkIds, 0);
129  Solver.impose(f, bdrIds, 0.1);
130  Solver.solve(f);
132  particles.write(p_output,BINARY);
133  Sdzz.deallocate(particles);
134  Sdyy.deallocate(particles);
135  Sdxx.deallocate(particles);
136  Sdz.deallocate(particles);
137  Sdy.deallocate(particles);
138  Sdx.deallocate(particles);
139 
140  tt.stop();
141  if (v_cl.rank() == 0)
142  std::cout << "Simulation took: " << tt.getcputime() << " s (CPU) - " << tt.getwct() << " s (wall)\n";
143 
144  openfpm_finalize();
145  return 0;
146 
147 }
Header file containing functions for creating files and folders.
static void create_directory_if_not_exist(std::string path, bool silent=0)
Creates a directory if not already existent.
This class represent an N-dimensional box.
Definition: Box.hpp:60
Definition: Ghost.hpp:40
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:28
Class for cpu time benchmarking.
Definition: timer.hpp:28
void stop()
Stop the timer.
Definition: timer.hpp:119
double getcputime()
Return the cpu time.
Definition: timer.hpp:142
void start()
Start the timer.
Definition: timer.hpp:90
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
Distributed vector.
bool write_frame(std::string out, size_t iteration, int opt=VTK_WRITER)
Output particle position and properties.
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
void ghost_get(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
bool write(std::string out, int opt=VTK_WRITER)
Output particle position and properties.
auto getLastProp() -> decltype(vPrp.template get< id >(0))
Get the property of the last element.
void add()
Add local particle.
void ghost_get_subset()
Stub does not do anything.
void deleteGhost()
Delete the particles on the ghost.
auto getLastPos() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element.
[v_transform metafunction]
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:221