OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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"
25
26std::string p_output;
27
28constexpr int DF=0;
29constexpr int F=1;
30constexpr int ANADF=2;
31constexpr int ERR=3;
32constexpr int NORMAL=4;
33constexpr int PCOORD=5;
34
36openfpm::vector<std::string> propNames{{"Df","f","AnaDf","error","Normal","PCOORD"}};
38
39int 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();
99
101 vector_dist_subset<3,double,prop> particles_boundary(particles,1);
102 auto &bulkIds=particles_bulk.getIds();
103 auto &bdrIds=particles_boundary.getIds();
104
105 auto DErr=getV<ERR>(particles);
106 auto Af=getV<ANADF>(particles);
107 auto Df=getV<DF>(particles);
108 auto f=getV<F>(particles);
109 auto N=getV<NORMAL>(particles);
110
111 SurfaceDerivative_x<NORMAL> Sdx{particles,2,rCut,grid_spacing_surf};
112 SurfaceDerivative_y<NORMAL> Sdy{particles,2,rCut,grid_spacing_surf};
113 SurfaceDerivative_z<NORMAL> Sdz{particles,2,rCut,grid_spacing_surf};
114
115 SurfaceDerivative_xx<NORMAL> Sdxx{particles,2,rCut,grid_spacing_surf};
116 SurfaceDerivative_yy<NORMAL> Sdyy{particles,2,rCut,grid_spacing_surf};
117 SurfaceDerivative_zz<NORMAL> Sdzz{particles,2,rCut,grid_spacing_surf};
118
119 DErr=-0.5*(Sdx(N[0])+Sdy(N[1])+Sdz(N[2]));
121 particles.write_frame(p_output,0,BINARY);
122
123
124 DCPSE_scheme<equations3d1, decltype(particles)> Solver(particles);
125 auto Eig = Sdxx(f)+Sdyy(f)+Sdzz(f)-EIGENVAL*f;
126 Solver.impose(Eig, bulkIds, 0);
127 Solver.impose(f, bdrIds, 0.1);
128 Solver.solve(f);
130 particles.write(p_output,BINARY);
131 Sdxx.deallocate(particles);
132 Sdyy.deallocate(particles);
133
134 tt.stop();
135 if (v_cl.rank() == 0)
136 std::cout << "Simulation took: " << tt.getcputime() << " s (CPU) - " << tt.getwct() << " s (wall)\n";
137
138 openfpm_finalize();
139 return 0;
140
141}
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:61
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
Implementation of 1-D std::vector like structure.
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.
auto getLastProp() -> decltype(v_prp.template get< id >(0))
Get the property of the last element.
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 getLastPos() -> decltype(v_pos.template get< 0 >(0))
Get the position of the last element.
void add()
Add local particle.
void deleteGhost()
Delete the particles on the ghost.
[v_transform metafunction]
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...