35 #include <emscripten.h>
36 #include <emscripten/bind.h>
38 #ifndef JS_CONVERT_ARRAYS
39 #define JS_CONVERT_ARRAYS
40 using namespace emscripten;
45 emscripten::val
to_js_array(
const std::vector<std::vector<T>>& data) {
46 using namespace emscripten;
47 val outer = val::array();
48 for (
size_t i = 0; i < data.size(); ++i) {
49 val inner = val::array();
50 for (
size_t j = 0; j < data[i].size(); ++j) {
51 inner.set(j, data[i][j]);
58 emscripten::val
to_js_array(
const std::vector<T>& data) {
59 using namespace emscripten;
60 val outer = val::array();
61 for (
size_t i = 0; i < data.size(); ++i) {
62 outer.set(i, data[i]);
68 std::vector<double> vec;
69 size_t length = jsArray[
"length"].as<
unsigned>();
71 for (
unsigned i = 0; i < length; ++i) {
72 vec.push_back(jsArray[i].as<double>());
80 template <
typename T> std::vector<std::vector<T>>
to_js_array(std::vector<std::vector<T>>& data) {
return data ; }
81 template <
typename T> std::vector<T>
to_js_array(std::vector<T>& data) {
return data ; }
82 template <
typename T> std::vector<T>
from_js_array(std::vector<T>& data) {
return data ; }
111 extern vector <std::pair<ExportType,ExportData>> *
toclean ;
120 std::vector < std::vector <double> >
X ;
121 std::vector < std::vector <double> >
V ;
122 std::vector < std::vector <double> >
A ;
123 std::vector < std::vector <double> >
Omega ;
124 std::vector < std::vector <double> >
F ;
125 std::vector < std::vector <double> >
FOld ;
126 std::vector < std::vector <double> >
Torque ;
130 std::vector < double >
Z ;
131 std::vector < std::vector <double> >
Fcorr ;
158 std::ofstream os(filename, std::ios::binary);
165 std::ifstream os(filename, std::ios::binary);
166 std::cout <<
"FILEOPEN:" << filename <<
" " << os.is_open() <<
"\n" ; fflush(stdout) ;
173 const char* env_p = std::getenv(
"OMP_NUM_THREADS") ;
174 if (env_p!=
nullptr) numthread = atoi (env_p) ;
175 omp_set_num_threads(numthread) ;
191 template <
class Archive>
195 CEREAL_NVP(X), V, A, Omega, F, FOld, Torque, TorqueOld, Vmag, OmegaMag, Z, Fcorr, TorqueCorr, RigidBodyId,
196 PBCFlags, WallForce, empty_array, ParticleForce, Ghost, Ghost_dir, Atmp,
197 numthread, t, ti, dt, tnow, tprevious,
198 P, MP, cells, ExternalAction, octree
208 assert(
d<(
static_cast<int>(
sizeof(
int))*8-1)) ;
211 X.resize(
N, std::vector <double> (
d, 0)) ;
213 V.resize(
N, std::vector <double> (
d, 0)) ;
214 A.resize(
N, std::vector <double> (
d*
d, 0)) ;
for (
int i=0 ; i<N ; i++) A[i]=Tools<d>::Eye ;
215 Omega.resize(
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
216 F.resize(
N, std::vector <double> (
d, 0)) ;
217 FOld.resize(
N, std::vector <double> (
d, 0)) ;
218 Torque.resize(
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
219 TorqueOld.resize(
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
222 OmegaMag.resize (
N,0) ;
224 Fcorr.resize (
N, std::vector <double> (
d, 0)) ;
225 TorqueCorr.resize (
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
226 RigidBodyId.resize(
N,{}) ;
228 PBCFlags.resize (
N, 0) ;
229 WallForce.resize (2*
d, std::vector <double> (
d,0)) ;
230 empty_array.resize(1, std::vector <double> (1, 0)) ;
232 Ghost.resize (
N, 0) ;
233 Ghost_dir.resize (
N, 0) ;
235 Atmp.resize (
d*
d, 0) ;
256 for (
auto v : P.
dumps)
265 const char* env_p = std::getenv(
"OMP_NUM_THREADS") ;
266 if (env_p!=
nullptr) numthread = atoi (env_p) ;
267 omp_set_num_threads(numthread) ;
274 printf(
"INITIALISE CELLS\n") ; fflush(stdout) ;
275 auto rmax = std::max_element(P.
r.begin(), P.
r.end()) ;
276 printf(
"%g ", *rmax) ;
283 printf(
"INITIALISE OCTREE\n") ; fflush(stdout) ;
309 int nsteps = P.
T/dt ;
310 step_forward(nsteps) ;
319 for (
int ntt=0 ; ntt<nt ; ntt++, t+=dt, ti++)
325 bool isdumptime = (ntt==nt-1) || (ti % P.
tdump==0) ;
330 printf(
"\r%10g | %5.2g%% | %d iterations in %10gs | %5d | finish in %10gs",t, t/P.
T*100, P.
tinfo,
331 double(tnow - tprevious) / CLOCKS_PER_SEC, ti, ((P.
T-t)/(P.
tinfo*dt))*(
double(tnow - tprevious) / CLOCKS_PER_SEC)) ;
338 #pragma omp parallel for default(none) shared (N) shared(X) shared(P) shared(V) shared(FOld) shared(Omega) shared(PBCFlags) shared(dt) shared(Ghost) shared(Ghost_dir) shared(A)
339 for (
int i=0 ; i<
N ; i++)
341 double disp, totdisp=0 ;
342 for (
int dd=0 ; dd<
d ; dd++)
344 disp = V[i][dd]*dt + FOld[i][dd] * (dt * dt / P.
m[i] /2.) ;
346 totdisp += disp*disp ;
354 v1d tmpO (
d*
d,0), tmpterm1 (
d*
d,0) ;
357 for (
int dd=0 ; dd<
d*
d ; dd++)
358 A[i][dd] -= tmpterm1[dd] * dt ;
367 Ghost[i]=0 ; Ghost_dir[i]=0 ;
370 for (
size_t j=0 ; j<P.
Boundaries.size() ; j++, mask<<=1)
372 if (!P.
Boundaries[j].is_periodic()) continue ;
373 if (X[i][j] <= P.
Boundaries[j].xmin + P.
r[i]) {Ghost[i] |= mask ; }
374 else if (X[i][j] >= P.
Boundaries[j].xmax - P.
r[i]) {Ghost[i] |= mask ; Ghost_dir[i] |= mask ;}
380 double tmpyloc = X[i][1] + (Ghost_dir[i]&1?-1:1)*P.
Boundaries[0].displacement ;
383 if (tmpyloc <= P.
Boundaries[1].xmin + P.
r[i]) {Ghost[i] |= mask ; }
384 else if (tmpyloc >= P.
Boundaries[1].xmax - P.
r[i]) {Ghost[i] |= mask ; Ghost_dir[i] |= mask ;}
401 double LE_displacement ;
403 LE_displacement = P.
Boundaries[0].displacement ;
405 LE_displacement = 0 ;
407 for (
int i=0 ; i<MP.
P ; i++)
408 MP.
CLp_it.it_ends[i] = MP.
CLp[i].v.end() ;
410 #pragma omp parallel default(none) shared(MP) shared(P) shared(N) shared(X) shared(Ghost) shared(Ghost_dir) shared(RigidBodyId) shared (stdout) shared(cells) shared(LE_displacement)
415 int ID = omp_get_thread_num();
416 double timebeg = omp_get_wtime();
418 cpm<d> tmpcpm(0,0,0,0,
nullptr) ;
419 cp<d> tmpcp(0,0,0,
nullptr) ;
double sum=0 ;
437 for (
int i=MP.
share[ID] ; i<MP.
share[ID+1] ; i++)
442 for (
int j=i+1 ; j<
N ; j++)
445 if (RigidBodyId[i].has_value() && RigidBodyId[j].has_value() && RigidBodyId[i]==RigidBodyId[j]) continue ;
446 if (Ghost[j] | Ghost[i])
448 tmpcp.
j=j ; tmpcp.
ghostdir=Ghost_dir[j] | (Ghost[i]&(~Ghost_dir[i])) ;
449 bitdim tmpghost = Ghost[j] | Ghost[i] ;
455 if (tmpyloc <= P.
Boundaries[1].xmin + P.
r[i]) {tmpghost |= (1<<30) ; }
456 else if (tmpyloc >= P.
Boundaries[1].xmax - P.
r[i]) {tmpghost |= (1<<30) ; tmpcp.
ghostdir |= (1<<30) ;}
460 (CLp.*CLp.
check_ghost) (tmpghost, P, X[i], X[j], P.
r[i], P.
r[j], tmpcp, 0,0,0) ;
465 for (
int k=0 ; sum<(P.
r[i]+P.
r[j])*(P.
r[i]+P.
r[j]) && k<
d ; k++) sum+= (X[i][k]-X[j][k])*(X[i][k]-X[j][k]) ;
466 if (sum<(P.
r[i]+P.
r[j])*(P.
r[i]+P.
r[j]))
477 for (
int i=MP.
share[ID] ; i<MP.
share[ID+1] ; i++)
481 tmpcp.
i=i ; tmpcp.
ghost=0 ;
482 for (
size_t j=0 ; j<P.
Boundaries.size() ; j++)
507 for (
int dd=0 ; dd<
d ; dd++)
524 for (
int dd=0 ; dd<
d ; dd++)
541 static_assert((
sizeof(
double)==8)) ;
548 #pragma GCC diagnostic push
549 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
552 #pragma GCC diagnostic pop
561 for (
size_t j=0 ; j<P.
Meshes.size() ; j++)
581 for (
int i=0 ; i<
N ; i++)
582 MP.
CLp_it.it_array_beg[i] = MP.
CLp_it.null_list.v.begin() ;
591 for (
auto it = ExternalAction.begin() ; it<ExternalAction.end() ; )
598 ExternalAction.erase(it) ;
604 #pragma omp parallel default(none) shared(MP) shared(P) shared(X) shared(V) shared(Omega) shared(F) shared(Fcorr) shared(TorqueCorr) shared(Torque) shared(stdout) shared(isdumptime)
609 int ID = omp_get_thread_num();
610 double timebeg = omp_get_wtime();
614 v1d tmpcn (
d,0) ;
v1d tmpvel (
d,0) ;
619 for (
auto it = CLp.
v.begin() ; it!=CLp.
v.end() ; it++)
622 while (it != CLp.
v.end() && !it->persisting)
623 it = CLp.
v.erase(it) ;
624 if (it == CLp.
v.end())
629 MP.
CLp_it.it_array_beg[it->i] = it ;
637 X[it->j], V[it->j], Omega[it->j], P.
r[it->j], P.
m[it->j], *it, isdumptime) ;
642 (C.*C.
particle_ghost) (X[it->i], V[it->i], Omega[it->i], P.
r[it->i], P.
m[it->i],
643 X[it->j], V[it->j], Omega[it->j], P.
r[it->j], P.
m[it->j], *it, isdumptime);
645 if (isdumptime) it->saveinfo(C.
Act) ;
658 it->persisting = false ;
667 for (
auto it = CLw.
v.begin() ; it!=CLw.
v.end() ; it++)
674 for (
int dd = 0 ; dd<
d ; dd++)
675 tmpcn[dd] = (X[it->i][dd]-P.
Boundaries[it->j/2].center[dd])*((it->j%2==0)?-1:1) ;
677 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
682 for (
int dd = 0 ; dd<
d ; dd++)
684 if (dd == P.
Boundaries[it->j/2].axis) continue ;
685 tmpcn[dd] = (X[it->i][dd]-P.
Boundaries[it->j/2].center[dd])*((it->j%2==0)?-1:1) ;
688 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
692 for (
int dd = 0 ; dd<
d ; dd++)
693 tmpcn[dd] = (X[it->i][dd]-P.
Boundaries[it->j/2].center[dd])*((it->j%2==0)?-1:1) ;
702 std::vector<double> tmpcn(2) ;
703 #pragma GCC diagnostic push
704 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
706 double tparam = *
reinterpret_cast<double*
>(&c) ;
707 #pragma GCC diagnostic pop
710 tmpcn/=
sqrt(tmpcn[0]*tmpcn[0]+tmpcn[1]*tmpcn[1]);
711 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
717 tmpcn=tmpcn*(-((it->j%2==0)?-1:1)) ;
718 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
731 for (
auto it = CLm.
v.begin() ; it != CLm.
v.end() ; it++)
734 C.
particle_mesh ( X[it->i], V[it->i], Omega[it->i], P.
r[it->i], P.
m[it->i], *it) ;
747 for (
int i=0 ; i<MP.
P ; i++)
765 #pragma omp parallel for default(none) shared(N) shared(P) shared(V) shared(Omega) shared(F) shared(FOld) shared(Torque) shared(TorqueOld) shared(dt)
766 for (
int i=0 ; i<
N ; i++)
779 TorqueOld[i]=Torque[i] ;
792 for (
int i=0 ; i<MP.
P ; i++)
801 P.
dumphandling (ti, t, X, V, Vmag, A, Omega, OmegaMag, PBCFlags, Z, MP) ;
802 std::fill(PBCFlags.begin(), PBCFlags.end(), 0);
806 char path[5000] ; sprintf(path,
"%s/LogWallForce-%05d.txt", P.
Directory.c_str(), ti) ;
809 for (
int i=0 ; i<MP.
P ; i++)
813 Tools<d>::savetxt(path, WallForce, (
char const *)(
"Force on the various walls")) ;
853 printf(
"This is the end ...\n") ;
922 for (
int i=0 ; i<
d ; i++) {
930 for (
int i=0; i<(
d*(
d-1)/2); i++) {
931 Omega[id][i] = omega2[i];
939 for (
int i=0 ; i<
d ; i++) {
943 for (
int i=0; i<(
d*(
d-1)/2); i++) {
994 printf(
"\nSetting the force: %g %g %g %g\n", force2[0],force2[1],force2[2],force2[3]);
995 ExternalAction.resize(ExternalAction.size()+1) ;
996 ExternalAction[ExternalAction.size()-1].id = id ;
997 ExternalAction[ExternalAction.size()-1].duration = duration ;
998 ExternalAction[ExternalAction.size()-1].set(force2,
v1d(
d,0),
v1d(
d*(
d-1)/2,0),
v1d(
d*(
d-1)/2,0)) ;
1003 unsigned long int seed = 5489UL ;
1004 boost::random::mt19937
rng(seed);
1005 boost::random::uniform_01<boost::mt19937> rand(
rng) ;
1006 for (
int i=0 ; i<
N ; i++)
1008 for(
int dd=0 ; dd <
d ; dd++)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: ArrayCwiseUnaryOps.h:187
EIGEN_DEVICE_FUNC const CosReturnType cos() const
Definition: ArrayCwiseUnaryOps.h:237
EIGEN_DEVICE_FUNC const SinReturnType sin() const
Definition: ArrayCwiseUnaryOps.h:255
std::vector< T > from_js_array(std::vector< T > &data)
Definition: DEMND.h:82
std::vector< std::vector< double > > Vector2Djs
Definition: DEMND.h:78
std::vector< double > Vector1Djs
Definition: DEMND.h:79
std::vector< std::vector< T > > to_js_array(std::vector< std::vector< T >> &data)
Definition: DEMND.h:80
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:25318
boost::random::mt19937 rng(static_cast< unsigned int >(std::time(nullptr)))
Binary input and output archives.
#define CEREAL_NVP(T)
Creates a name value pair for the variable T with the same name as the variable.
Definition: cereal.hpp:72
Support for types found in <chrono>
All the cells making the space, with related function for creating the cell array,...
Definition: Cells.h:44
int contacts(int ID, std::pair< int, int > bounds, CLp_it_t< d > &CLp_it, ContactList< d > &CLnew, std::vector< std::vector< double >> const &X, std::vector< double > const &r, double LE_displacement)
Definition: Cells.h:482
int allocate_to_cells(std::vector< std::vector< double >> &X)
Definition: Cells.h:432
std::vector< Cell > cells
Definition: Cells.h:141
int init_cells(std::vector< Boundary< d >> &boundaries, double ds)
Definition: Cells.h:236
Manual multiprocessor handling for OpenMP, for max efficiency & avoiding bugs & race conditions,...
Definition: Multiproc.h:60
vector< uint > delayed_size
Max length of the delayed vector for each thread. Can grow as needed on call to delaying()
Definition: Multiproc.h:285
vector< double > timing_contacts
Definition: Multiproc.h:278
int P
Number of threads.
Definition: Multiproc.h:291
vector< Contacts< d > > C
Dummy Contacts for independent calculation per processor.
Definition: Multiproc.h:275
vector< uint > delayedwall_size
Max length of the delayed wall vector for each thread. Can grow as needed on call to delaying()
Definition: Multiproc.h:289
vector< vector< Action< d > > > delayedwall
Records the delayed Action.
Definition: Multiproc.h:287
vector< ContactListMesh< d > > CLm
ContactList particle-mesh for each processor.
Definition: Multiproc.h:274
vector< vector< Action< d > > > delayed
Records the delayed Action.
Definition: Multiproc.h:283
vector< ContactList< d > > CLp
ContactList particle-particle for each processor.
Definition: Multiproc.h:271
void merge_newcontacts()
Definition: Multiproc.h:94
vector< int > share
Particle share between threads. A thread ID own particles with index between share[ID] and share[ID+1...
Definition: Multiproc.h:276
vector< ContactList< d > > CLw
ContactList particle-wall for each processor.
Definition: Multiproc.h:273
CLp_it_t< d > CLp_it
Iterator list for fast access to particle contacts.
Definition: Multiproc.h:280
bool ismine(int ID, int j)
Check if a particle j belongs to the thread ID.
Definition: Multiproc.h:87
int num_time
Number of sample of time spent. Resets when load_balance() is called.
Definition: Multiproc.h:279
vector< int > sharecell
Cell share between threads (for contact detection based on cells). A thread ID own cells with index b...
Definition: Multiproc.h:277
vector< double > timing_forces
Used to record the time spent by each thread.
Definition: Multiproc.h:278
vector< vector< int > > delayedj
Records the j id of the particle in the associated delayed action.
Definition: Multiproc.h:284
vector< ContactList< d > > CLp_new
New particle-particle contacts for each processor.
Definition: Multiproc.h:272
vector< vector< int > > delayedwallj
Records the j id of the wall in the associated delayed action.
Definition: Multiproc.h:288
void initialise(int NN, int PP, Parameters< d > &Param)
Definition: Multiproc.h:63
int init_cells(std::vector< Boundary< d >> &boundaries, std::vector< double > &r)
Definition: Octree.h:13
int contacts(int ID, std::pair< int, int > bounds, CLp_it_t< d > &CLp_it, ContactList< d > &CLnew, std::vector< std::vector< double >> const &X, std::vector< double > const &r, double LE_displacement)
Definition: Octree.h:78
int cells_to_split()
Definition: Octree.h:42
int allocate_to_cells(std::vector< std::vector< double >> &X)
Definition: Octree.h:58
Generic class to handle the simulation set up.
Definition: Parameters.h:128
ContactStrategies contact_strategy
Strategy for the contact detection.
Definition: Parameters.h:188
vector< double > g
Gravity vector.
Definition: Parameters.h:197
int n_restart
Restart writing frequency.
Definition: Parameters.h:212
bool orientationtracking
Track orientation?
Definition: Parameters.h:201
void load_datafile(char path[], v2d &X, v2d &V, v2d &Omega)
Load and parse input script.
Definition: Parameters.h:446
XMLWriter * xmlout
Pointer to the (optional) xml dump object.
Definition: Parameters.h:190
void(Parameters::* update_gravity)(double time)
Definition: Parameters.h:264
bool perform_forceinsphere(v1d &X)
Definition: Parameters.h:382
void perform_PBCLE_move()
Definition: Parameters.h:358
double T
Run until this time (note it is a floating point).
Definition: Parameters.h:175
bool forceinsphere
Definition: Parameters.h:185
bool wallforcecompute
Compute for on the wall?
Definition: Parameters.h:202
vector< double > r
Particle radii.
Definition: Parameters.h:194
int N
Number of particles.
Definition: Parameters.h:172
RigidBodies_< d > RigidBodies
Handle all the rigid bodies.
Definition: Parameters.h:210
void perform_PBCLE(v1d &X, v1d &V, uint32_t &PBCFlag)
Definition: Parameters.h:335
int tinfo
Show detail information on scren every this many timesteps.
Definition: Parameters.h:174
bool wallforcerequested
Compute for on the wall?
Definition: Parameters.h:203
double graddesc_gamma
Decay rate parameters for the gradient descent algorithm.
Definition: Parameters.h:205
void finalise()
Close opened dump files.
Definition: Parameters.h:1241
string Directory
Saving directory.
Definition: Parameters.h:200
int dumphandling(int ti, double t, v2d &X, v2d &V, v1d &Vmag, v2d &A, v2d &Omega, v1d &OmegaMag, vector< uint32_t > &PBCFlags, v1d &Z, Multiproc< d > &MP)
Dump writing functions.
Definition: Parameters.h:1251
int set_boundaries()
Set default boundaries.
Definition: Parameters.h:308
double damping
Definition: Parameters.h:184
vector< bool > Frozen
Frozen atom if true.
Definition: Parameters.h:198
double dt
timestep
Definition: Parameters.h:176
void perform_PBC(v1d &X, uint32_t &PBCFlags)
Bring particle back in the simulation box if the grains cross the boundaries.
Definition: Parameters.h:322
vector< Mesh< d > > Meshes
Handle all meshes.
Definition: Parameters.h:211
std::string restart_filename
Restart filename.
Definition: Parameters.h:213
vector< double > m
Particle mass.
Definition: Parameters.h:195
double cellsize
Size of cells for contact detection.
Definition: Parameters.h:186
vector< Boundary< d > > Boundaries
List of boundaries. Second dimension is {min, max, length, type}.
Definition: Parameters.h:199
void check_events(float time, v2d &X, v2d &V, v2d &Omega)
Verify if an event triggers at the current time time.
Definition: Parameters.h:466
bool wallforcecomputed
Compute for on the wall?
Definition: Parameters.h:204
void interpret_command(istream &in, v2d &X, v2d &V, v2d &Omega)
Parse input script commands.
Definition: Parameters.h:496
double graddesc_tol
Tolerance for the gradient descent algorithm.
Definition: Parameters.h:206
vector< double > I
Particule moment of inertia.
Definition: Parameters.h:196
vector< std::pair< ExportType, ExportData > > dumps
Vector linking dump file and data dumped.
Definition: Parameters.h:189
void perform_MOVINGWALL()
Move the boundary wall if moving.
Definition: Parameters.h:369
double gravityrotateangle
Definition: Parameters.h:209
int tdump
Write dump file every this many timesteps.
Definition: Parameters.h:173
unsigned char restart_flag
Definition: Parameters.h:214
vector< uint32_t > Ghost_dir
Definition: DEMND.h:144
std::vector< std::vector< double > > FOld
Definition: DEMND.h:125
int N
Definition: DEMND.h:119
std::vector< double > Vmag
Definition: DEMND.h:128
v1d Atmp
Definition: DEMND.h:145
std::vector< std::vector< double > > Fcorr
Definition: DEMND.h:131
Cells< d > cells
Definition: DEMND.h:149
std::vector< std::vector< double > > V
Definition: DEMND.h:121
std::vector< std::vector< double > > A
Definition: DEMND.h:122
void serialize(Archive &ar)
Definition: DEMND.h:192
double dt
Definition: DEMND.h:153
Multiproc< d > MP
Definition: DEMND.h:148
std::vector< std::vector< double > > Torque
Definition: DEMND.h:126
std::vector< std::vector< double > > ParticleForce
Definition: DEMND.h:141
std::vector< uint32_t > PBCFlags
Definition: DEMND.h:138
void randomDrop()
Definition: DEMND.h:1001
void init_from_file(char filename[])
Initialise the simulation from a file.
Definition: DEMND.h:243
std::vector< double > Z
Definition: DEMND.h:130
std::vector< SpecificAction< d > > ExternalAction
Definition: DEMND.h:136
std::vector< std::optional< int > > RigidBodyId
Definition: DEMND.h:134
Octree< d > octree
Definition: DEMND.h:150
Simulation(int NN)
Definition: DEMND.h:204
double t
Definition: DEMND.h:152
vector< uint32_t > Ghost
Definition: DEMND.h:143
void save_restart(const std::string &filename)
Definition: DEMND.h:157
std::vector< std::vector< double > > empty_array
Definition: DEMND.h:140
std::vector< std::vector< double > > TorqueOld
Definition: DEMND.h:127
clock_t tnow
Definition: DEMND.h:154
std::vector< std::vector< double > > TorqueCorr
Definition: DEMND.h:132
std::vector< std::vector< double > > X
Definition: DEMND.h:120
Parameters< d > P
Definition: DEMND.h:118
std::vector< std::vector< double > > Omega
Definition: DEMND.h:123
void setBoundary(int a, Vector1Djs loc)
Definition: DEMND.h:965
std::vector< std::vector< double > > WallForce
Definition: DEMND.h:139
std::vector< double > OmegaMag
Definition: DEMND.h:129
void step_forward_all()
Run the whole simulation as defined in the input script.
Definition: DEMND.h:307
std::vector< std::vector< double > > F
Definition: DEMND.h:124
void load_restart(const std::string &filename)
Definition: DEMND.h:164
An output archive designed to save data in a compact binary representation.
Definition: binary.hpp:52
Contact properties class.
Definition: ContactList.h:69
double contactlength
Length of the contact.
Definition: ContactList.h:115
int j
Index of second contacting particle or wall. If this is a wall contact, j=2*walldimension + (0 or 1 i...
Definition: ContactList.h:114
int i
Index of contacting particle.
Definition: ContactList.h:113
void setinfo(Action< d > *a)
Set information for contact force.
Definition: ContactList.h:92
uint32_t ghost
Contain ghost information about ghost contact, cf detailed description.
Definition: ContactList.h:116
uint32_t ghostdir
Contain ghost information about ghost direction, cf detailed description.
Definition: ContactList.h:117
Contact properties for mesh contacts (mainly), including contact point location, specialising cp.
Definition: ContactList.h:177
void setRadius(int id, double radius)
Set the radius of a specific particle.
Definition: DEMND.h:865
void setFrozen(int a)
Freeze a single particle.
Definition: DEMND.h:949
Vector1Djs getBoundary(int a)
Expose the array of boundaries.
Definition: DEMND.h:964
Vector2Djs getWallForce()
Expose the array of wall forces.
Definition: DEMND.h:976
Vector1Djs getRadii()
Expose the array of radii.
Definition: DEMND.h:862
void interpret_command(string in)
Interpret individual script command from string.
Definition: DEMND.h:299
void step_forward(int nt)
Advance the simulation for nt steps (actual duration nt*dt).
Definition: DEMND.h:317
Vector2Djs getContactForce()
DEPRECATED: Use getContactInfo with the appropriate flags instead. Expose the array of particle id an...
Definition: DEMND.h:877
void setMass(int id, double mass)
Set the mass of a specific particle.
Definition: DEMND.h:868
Vector1Djs getRotationRate()
Expose the array of orientation rate.
Definition: DEMND.h:874
void setExternalForce(int id, int duration, Vector1Djs force)
Set an additional external force on a particle for a certain duration.
Definition: DEMND.h:990
Vector2Djs getOrientation()
Expose the array of orientation.
Definition: DEMND.h:961
void finalise()
Settles the simulation, closing open files etc.
Definition: DEMND.h:850
Vector2Djs getX()
Expose the array of locations.
Definition: DEMND.h:859
Vector2Djs getVelocity()
Expose the array of velocities.
Definition: DEMND.h:871
void setAngularVelocity(int id, Vector1Djs omega)
Set the angular velocity of a single particle.
Definition: DEMND.h:928
void setVelocity(int id, Vector1Djs vel)
Set the array of locations.
Definition: DEMND.h:920
double getGravityAngle()
Expose the current gravity angle.
Definition: DEMND.h:957
Vector2Djs getContactInfos(int flags)
Expose the array of contact information.
Definition: DEMND.h:884
void finalise_init()
Tell NDDEM that the simulations are now initialised and we can start running.
Definition: DEMND.h:252
double getTime()
Expose the current time.
Definition: DEMND.h:954
void fixParticle(int a, Vector1Djs loc)
Set a single particle location, velocity, and angular velocity.
Definition: DEMND.h:937
void delaying(int ID, int j, Action< d > &act)
Record the action to be added later to the relevent atom in sequencial settings, avoid potential race...
Definition: Multiproc.h:385
static void orthonormalise(v1d &A)
Orthonormalise A using the Gram-Shmidt process, in place.
Definition: Tools.h:741
static void setzero(v2d &a)
Set a matrix to zero in-place.
Definition: Tools.h:117
static void unitvec(vector< double > &v, int n)
Construct a unit vector in place.
Definition: Tools.h:735
void particle_particle(cv1d &Xi, cv1d &Vi, cv1d &Omegai, double ri, double mi, cv1d &Xj, cv1d &Vj, cv1d &Omegaj, double rj, double mj, cp< d > &Contact, bool isdumptime)
Force & torque between 2 particles.
Definition: Contacts.h:171
ExportData
Definition: Parameters.h:46
@ vel
Definition: Typedefs.h:19
@ omega
Definition: Typedefs.h:19
@ radius
Definition: Typedefs.h:19
@ mass
Definition: Typedefs.h:19
void particle_mesh(cv1d &Xi, cv1d &Vi, cv1d &Omegai, double ri, double mi, cpm< d > &Contact)
Force & torque between particle and mesh.
Definition: Contacts.h:401
void particle_movingwall(cv1d &Vi, cv1d &Omegai, double ri, double mi, cv1d &cn, cv1d &Vj, cp< d > &Contact)
Force & torque between a particle and a moving wall. Vj is the velocity of the wall at the contact po...
Definition: Contacts.h:331
static int savetxt(char path[], const v2d &table, char const header[])
Definition: Tools.h:349
void load_balance(ContactStrategies contactstrategy)
Modify the atom share between threads to achieve better load balance between the threads based on the...
Definition: Multiproc.h:437
unsigned int uint
Definition: Typedefs.h:8
void delayedwall_clean()
Clean the record of the force on the wal.
Definition: Multiproc.h:428
auto contacts2array(ExportData exp, cv2d &X, Parameters< d > &P)
pack the contact data in a 2d array
Definition: Multiproc.h:568
int insert(const cpm< d > &a)
Insert a contact, maintaining sorting with increasing i, and removing missing contacts on traversal.
Definition: ContactList.h:451
void delayed_clean()
Clean the record list.
Definition: Multiproc.h:420
int insert(const cp< d > &a)
Insert a contact, maintaining sorting with increasing i, and removing missing contacts on traversal.
Definition: ContactList.h:430
static v1d matmult(cv1d &A, cv1d &B)
Multiply 2 matrix together.
Definition: Tools.h:680
unsigned int bitdim
Definition: Typedefs.h:17
static v1d skewexpand(cv1d &A)
Return the skew symetrix matrix M stored on d(d-1)/2 component as a full flattened matrix with d^2 co...
Definition: Tools.h:660
vector< std::pair< ExportType, ExportData > > * toclean
Definition: DEMND.cpp:21
void particle_wall(cv1d &Vi, cv1d &Omegai, double ri, double mi, cv1d &cn, cp< d > &Contact)
Force & torque between a particle and a wall.
Definition: Contacts.h:261
void delayingwall(int ID, int j, Action< d > &act)
Record the action on the wall. Only usefull if the force on the wall needs to be calculated.
Definition: Multiproc.h:402
XMLWriter * xmlout
Definition: DEMND.cpp:22
static void setgravity(v2d &a, v1d &g, v1d &m)
Set the gravity. .
Definition: Tools.h:154
void splitcells(int C)
Definition: Multiproc.h:376
vector< double > v1d
Definition: Typedefs.h:9
static void surfacevelocity(v1d &res, cv1d &p, double *com, double *vel_com, double *omega_com)
Definition: Tools.h:131
static void initialise()
Initialise the member variables, in particular the variables to handle skew-symmetric flattened matri...
Definition: Tools.h:318
static double norm(const vector< double > &a)
Norm of a vector.
Definition: Tools.h:119
@ CELLS
Definition: Typedefs.h:22
@ OCTREE
Definition: Typedefs.h:22
Support for types found in <list>
Support for types found in <map>
Support for std::optional.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
unsigned int uint32_t
Definition: stdint.h:126
unsigned __int64 uint64_t
Definition: stdint.h:136
Support for types found in <string>
Support for types found in <utility>
Support for types found in <vector>
XML input and output archives.