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) ;
188 template <
class Archive>
192 CEREAL_NVP(X), V, A, Omega, F, FOld, Torque, TorqueOld, Vmag, OmegaMag, Z, Fcorr, TorqueCorr, RigidBodyId,
193 PBCFlags, WallForce, empty_array, ParticleForce, Ghost, Ghost_dir, Atmp,
194 numthread, t, ti, dt, tnow, tprevious,
195 P, MP, cells, ExternalAction, octree
205 assert(
d<(
static_cast<int>(
sizeof(
int))*8-1)) ;
208 X.resize(
N, std::vector <double> (
d, 0)) ;
210 V.resize(
N, std::vector <double> (
d, 0)) ;
211 A.resize(
N, std::vector <double> (
d*
d, 0)) ;
for (
int i=0 ; i<N ; i++) A[i]=Tools<d>::Eye ;
212 Omega.resize(
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
213 F.resize(
N, std::vector <double> (
d, 0)) ;
214 FOld.resize(
N, std::vector <double> (
d, 0)) ;
215 Torque.resize(
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
216 TorqueOld.resize(
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
219 OmegaMag.resize (
N,0) ;
221 Fcorr.resize (
N, std::vector <double> (
d, 0)) ;
222 TorqueCorr.resize (
N, std::vector <double> (
d*(
d-1)/2, 0)) ;
223 RigidBodyId.resize(
N,{}) ;
225 PBCFlags.resize (
N, 0) ;
226 WallForce.resize (2*
d, std::vector <double> (
d,0)) ;
227 empty_array.resize(1, std::vector <double> (1, 0)) ;
229 Ghost.resize (
N, 0) ;
230 Ghost_dir.resize (
N, 0) ;
232 Atmp.resize (
d*
d, 0) ;
258 const char* env_p = std::getenv(
"OMP_NUM_THREADS") ;
259 if (env_p!=
nullptr) numthread = atoi (env_p) ;
260 omp_set_num_threads(numthread) ;
267 printf(
"INITIALISE CELLS\n") ; fflush(stdout) ;
268 auto rmax = std::max_element(P.
r.begin(), P.
r.end()) ;
269 printf(
"%g ", *rmax) ;
276 printf(
"INITIALISE OCTREE\n") ; fflush(stdout) ;
302 int nsteps = P.
T/dt ;
303 step_forward(nsteps) ;
312 for (
int ntt=0 ; ntt<nt ; ntt++, t+=dt, ti++)
318 bool isdumptime = (ntt==nt-1) || (ti % P.
tdump==0) ;
323 printf(
"\r%10g | %5.2g%% | %d iterations in %10gs | %5d | finish in %10gs",t, t/P.
T*100, P.
tinfo,
324 double(tnow - tprevious) / CLOCKS_PER_SEC, ti, ((P.
T-t)/(P.
tinfo*dt))*(
double(tnow - tprevious) / CLOCKS_PER_SEC)) ;
331 #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)
332 for (
int i=0 ; i<
N ; i++)
334 double disp, totdisp=0 ;
335 for (
int dd=0 ; dd<
d ; dd++)
337 disp = V[i][dd]*dt + FOld[i][dd] * (dt * dt / P.
m[i] /2.) ;
339 totdisp += disp*disp ;
347 v1d tmpO (
d*
d,0), tmpterm1 (
d*
d,0) ;
350 for (
int dd=0 ; dd<
d*
d ; dd++)
351 A[i][dd] -= tmpterm1[dd] * dt ;
360 Ghost[i]=0 ; Ghost_dir[i]=0 ;
363 for (
size_t j=0 ; j<P.
Boundaries.size() ; j++, mask<<=1)
365 if (!P.
Boundaries[j].is_periodic()) continue ;
366 if (X[i][j] <= P.
Boundaries[j].xmin + P.
r[i]) {Ghost[i] |= mask ; }
367 else if (X[i][j] >= P.
Boundaries[j].xmax - P.
r[i]) {Ghost[i] |= mask ; Ghost_dir[i] |= mask ;}
373 double tmpyloc = X[i][1] + (Ghost_dir[i]&1?-1:1)*P.
Boundaries[0].displacement ;
376 if (tmpyloc <= P.
Boundaries[1].xmin + P.
r[i]) {Ghost[i] |= mask ; }
377 else if (tmpyloc >= P.
Boundaries[1].xmax - P.
r[i]) {Ghost[i] |= mask ; Ghost_dir[i] |= mask ;}
394 double LE_displacement ;
396 LE_displacement = P.
Boundaries[0].displacement ;
398 LE_displacement = 0 ;
400 for (
int i=0 ; i<MP.
P ; i++)
401 MP.
CLp_it.it_ends[i] = MP.
CLp[i].v.end() ;
403 #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)
408 int ID = omp_get_thread_num();
409 double timebeg = omp_get_wtime();
411 cpm<d> tmpcpm(0,0,0,0,
nullptr) ;
412 cp<d> tmpcp(0,0,0,
nullptr) ;
double sum=0 ;
430 for (
int i=MP.
share[ID] ; i<MP.
share[ID+1] ; i++)
435 for (
int j=i+1 ; j<
N ; j++)
438 if (RigidBodyId[i].has_value() && RigidBodyId[j].has_value() && RigidBodyId[i]==RigidBodyId[j]) continue ;
439 if (Ghost[j] | Ghost[i])
441 tmpcp.
j=j ; tmpcp.
ghostdir=Ghost_dir[j] | (Ghost[i]&(~Ghost_dir[i])) ;
442 bitdim tmpghost = Ghost[j] | Ghost[i] ;
448 if (tmpyloc <= P.
Boundaries[1].xmin + P.
r[i]) {tmpghost |= (1<<30) ; }
449 else if (tmpyloc >= P.
Boundaries[1].xmax - P.
r[i]) {tmpghost |= (1<<30) ; tmpcp.
ghostdir |= (1<<30) ;}
453 (CLp.*CLp.
check_ghost) (tmpghost, P, X[i], X[j], P.
r[i], P.
r[j], tmpcp, 0,0,0) ;
458 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]) ;
459 if (sum<(P.
r[i]+P.
r[j])*(P.
r[i]+P.
r[j]))
470 for (
int i=MP.
share[ID] ; i<MP.
share[ID+1] ; i++)
474 tmpcp.
i=i ; tmpcp.
ghost=0 ;
475 for (
size_t j=0 ; j<P.
Boundaries.size() ; j++)
500 for (
int dd=0 ; dd<
d ; dd++)
517 for (
int dd=0 ; dd<
d ; dd++)
534 static_assert((
sizeof(
double)==8)) ;
541 #pragma GCC diagnostic push
542 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
545 #pragma GCC diagnostic pop
554 for (
size_t j=0 ; j<P.
Meshes.size() ; j++)
574 for (
int i=0 ; i<
N ; i++)
575 MP.
CLp_it.it_array_beg[i] = MP.
CLp_it.null_list.v.begin() ;
584 for (
auto it = ExternalAction.begin() ; it<ExternalAction.end() ; )
591 ExternalAction.erase(it) ;
597 #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)
602 int ID = omp_get_thread_num();
603 double timebeg = omp_get_wtime();
607 v1d tmpcn (
d,0) ;
v1d tmpvel (
d,0) ;
612 for (
auto it = CLp.
v.begin() ; it!=CLp.
v.end() ; it++)
615 while (it != CLp.
v.end() && !it->persisting)
616 it = CLp.
v.erase(it) ;
617 if (it == CLp.
v.end())
622 MP.
CLp_it.it_array_beg[it->i] = it ;
630 X[it->j], V[it->j], Omega[it->j], P.
r[it->j], P.
m[it->j], *it, isdumptime) ;
635 (C.*C.
particle_ghost) (X[it->i], V[it->i], Omega[it->i], P.
r[it->i], P.
m[it->i],
636 X[it->j], V[it->j], Omega[it->j], P.
r[it->j], P.
m[it->j], *it, isdumptime);
638 if (isdumptime) it->saveinfo(C.
Act) ;
651 it->persisting = false ;
660 for (
auto it = CLw.
v.begin() ; it!=CLw.
v.end() ; it++)
667 for (
int dd = 0 ; dd<
d ; dd++)
668 tmpcn[dd] = (X[it->i][dd]-P.
Boundaries[it->j/2].center[dd])*((it->j%2==0)?-1:1) ;
670 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
675 for (
int dd = 0 ; dd<
d ; dd++)
677 if (dd == P.
Boundaries[it->j/2].axis) continue ;
678 tmpcn[dd] = (X[it->i][dd]-P.
Boundaries[it->j/2].center[dd])*((it->j%2==0)?-1:1) ;
681 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
685 for (
int dd = 0 ; dd<
d ; dd++)
686 tmpcn[dd] = (X[it->i][dd]-P.
Boundaries[it->j/2].center[dd])*((it->j%2==0)?-1:1) ;
695 std::vector<double> tmpcn(2) ;
696 #pragma GCC diagnostic push
697 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
699 double tparam = *
reinterpret_cast<double*
>(&c) ;
700 #pragma GCC diagnostic pop
701 tmpcn[0]=X[it->i][0]-(P.
Boundaries[it->j/2].centerx+P.
Boundaries[it->j/2].semiaxisx*cos(tparam)) ;
702 tmpcn[1]=X[it->i][1]-(P.
Boundaries[it->j/2].centery+P.
Boundaries[it->j/2].semiaxisy*sin(tparam)) ;
703 tmpcn/=sqrt(tmpcn[0]*tmpcn[0]+tmpcn[1]*tmpcn[1]);
704 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
710 tmpcn=tmpcn*(-((it->j%2==0)?-1:1)) ;
711 C.
particle_wall( V[it->i],Omega[it->i],P.
r[it->i], P.
m[it->i], tmpcn, *it) ;
724 for (
auto it = CLm.
v.begin() ; it != CLm.
v.end() ; it++)
727 C.
particle_mesh ( X[it->i], V[it->i], Omega[it->i], P.
r[it->i], P.
m[it->i], *it) ;
740 for (
int i=0 ; i<MP.
P ; i++)
758 #pragma omp parallel for default(none) shared(N) shared(P) shared(V) shared(Omega) shared(F) shared(FOld) shared(Torque) shared(TorqueOld) shared(dt)
759 for (
int i=0 ; i<
N ; i++)
772 TorqueOld[i]=Torque[i] ;
785 for (
int i=0 ; i<MP.
P ; i++)
794 P.
dumphandling (ti, t, X, V, Vmag, A, Omega, OmegaMag, PBCFlags, Z, MP) ;
795 std::fill(PBCFlags.begin(), PBCFlags.end(), 0);
799 char path[5000] ; sprintf(path,
"%s/LogWallForce-%05d.txt", P.
Directory.c_str(), ti) ;
802 for (
int i=0 ; i<MP.
P ; i++)
806 Tools<d>::savetxt(path, WallForce, (
char const *)(
"Force on the various walls")) ;
846 printf(
"This is the end ...\n") ;
915 for (
int i=0 ; i<
d ; i++) {
923 for (
int i=0; i<(
d*(
d-1)/2); i++) {
924 Omega[id][i] = omega2[i];
932 for (
int i=0 ; i<
d ; i++) {
936 for (
int i=0; i<(
d*(
d-1)/2); i++) {
987 printf(
"\nSetting the force: %g %g %g %g\n", force2[0],force2[1],force2[2],force2[3]);
988 ExternalAction.resize(ExternalAction.size()+1) ;
989 ExternalAction[ExternalAction.size()-1].id = id ;
990 ExternalAction[ExternalAction.size()-1].duration = duration ;
991 ExternalAction[ExternalAction.size()-1].set(force2,
v1d(
d,0),
v1d(
d*(
d-1)/2,0),
v1d(
d*(
d-1)/2,0)) ;
996 unsigned long int seed = 5489UL ;
997 boost::random::mt19937
rng(seed);
998 boost::random::uniform_01<boost::mt19937> rand(
rng) ;
999 for (
int i=0 ; i<
N ; i++)
1001 for(
int dd=0 ; dd <
d ; dd++)
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:195
int n_restart
Restart writing frequency.
Definition: Parameters.h:210
bool orientationtracking
Track orientation?
Definition: Parameters.h:199
void load_datafile(char path[], v2d &X, v2d &V, v2d &Omega)
Load and parse input script.
Definition: Parameters.h:507
XMLWriter * xmlout
Definition: Parameters.h:371
void(Parameters::* update_gravity)(double time)
Definition: Parameters.h:265
bool perform_forceinsphere(v1d &X)
Definition: Parameters.h:231
void perform_PBCLE_move()
Definition: Parameters.h:448
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:200
vector< double > r
Particle radii.
Definition: Parameters.h:192
int N
Number of particles.
Definition: Parameters.h:172
RigidBodies_< d > RigidBodies
Handle all the rigid bodies.
Definition: Parameters.h:208
void perform_PBCLE(v1d &X, v1d &V, uint32_t &PBCFlag)
Definition: Parameters.h:425
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:201
double graddesc_gamma
Decay rate parameters for the gradient descent algorithm.
Definition: Parameters.h:203
void finalise()
Close opened dump files.
Definition: Parameters.h:1306
string Directory
Saving directory.
Definition: Parameters.h:198
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:1316
int set_boundaries()
Set default boundaries.
Definition: Parameters.h:398
double damping
Definition: Parameters.h:184
vector< bool > Frozen
Frozen atom if true.
Definition: Parameters.h:196
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:412
vector< Mesh< d > > Meshes
Handle all meshes.
Definition: Parameters.h:209
std::string restart_filename
Restart filename.
Definition: Parameters.h:211
vector< double > m
Particle mass.
Definition: Parameters.h:193
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:197
void check_events(float time, v2d &X, v2d &V, v2d &Omega)
Verify if an event triggers at the current time time.
Definition: Parameters.h:531
bool wallforcecomputed
Compute for on the wall?
Definition: Parameters.h:202
void interpret_command(istream &in, v2d &X, v2d &V, v2d &Omega)
Parse input script commands.
Definition: Parameters.h:561
double graddesc_tol
Tolerance for the gradient descent algorithm.
Definition: Parameters.h:204
vector< double > I
Particule moment of inertia.
Definition: Parameters.h:194
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:459
double gravityrotateangle
Definition: Parameters.h:207
int tdump
Write dump file every this many timesteps.
Definition: Parameters.h:173
unsigned char restart_flag
Definition: Parameters.h:212
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:189
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:994
void init_from_file(char filename[])
Initialise the simulation from a file.
Definition: DEMND.h:240
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:201
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:958
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:300
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:858
void setFrozen(int a)
Freeze a single particle.
Definition: DEMND.h:942
Vector1Djs getBoundary(int a)
Expose the array of boundaries.
Definition: DEMND.h:957
Vector2Djs getWallForce()
Expose the array of wall forces.
Definition: DEMND.h:969
Vector1Djs getRadii()
Expose the array of radii.
Definition: DEMND.h:855
void interpret_command(string in)
Interpret individual script command from string.
Definition: DEMND.h:292
void step_forward(int nt)
Advance the simulation for nt steps (actual duration nt*dt).
Definition: DEMND.h:310
Vector2Djs getContactForce()
DEPRECATED: Use getContactInfo with the appropriate flags instead. Expose the array of particle id an...
Definition: DEMND.h:870
void setMass(int id, double mass)
Set the mass of a specific particle.
Definition: DEMND.h:861
Vector1Djs getRotationRate()
Expose the array of orientation rate.
Definition: DEMND.h:867
void setExternalForce(int id, int duration, Vector1Djs force)
Set an additional external force on a particle for a certain duration.
Definition: DEMND.h:983
Vector2Djs getOrientation()
Expose the array of orientation.
Definition: DEMND.h:954
void finalise()
Settles the simulation, closing open files etc.
Definition: DEMND.h:843
Vector2Djs getX()
Expose the array of locations.
Definition: DEMND.h:852
Vector2Djs getVelocity()
Expose the array of velocities.
Definition: DEMND.h:864
void setAngularVelocity(int id, Vector1Djs omega)
Set the angular velocity of a single particle.
Definition: DEMND.h:921
void setVelocity(int id, Vector1Djs vel)
Set the array of locations.
Definition: DEMND.h:913
double getGravityAngle()
Expose the current gravity angle.
Definition: DEMND.h:950
Vector2Djs getContactInfos(int flags)
Expose the array of contact information.
Definition: DEMND.h:877
void finalise_init()
Tell NDDEM that the simulations are now initialised and we can start running.
Definition: DEMND.h:249
double getTime()
Expose the current time.
Definition: DEMND.h:947
void fixParticle(int a, Vector1Djs loc)
Set a single particle location, velocity, and angular velocity.
Definition: DEMND.h:930
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.