Parallel Finite Element - General geometry Ewald-like Method
Part of Continuum-particle Simulation Suite under MICCOM
copss.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2016 Xujun Zhao, Jiyuan Li, Xikai Jiang
2 
3 // This code is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 
8 
9 // This code is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 
15 // You should have received a copy of the GNU General Public
16 // License along with this code; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #pragma once
19 
20 // C++ includes
21 #include <iostream>
22 #include <algorithm>
23 #include <cstring>
24 #include <math.h>
25 #include <time.h>
26 #include <fstream>
27 #include <tuple>
28 #include <stdlib.h>
29 
30 // Libmesh includes
31 #include "libmesh/libmesh.h"
32 #include "libmesh/libmesh_config.h"
33 #include "libmesh/getpot.h"
34 #include "libmesh/exodusII_io.h"
35 #include "libmesh/enum_solver_package.h"
36 
37 #include "libmesh/serial_mesh.h"
38 #include "libmesh/mesh_generation.h"
39 #include "libmesh/mesh_modification.h"
40 #include "libmesh/mesh_refinement.h"
41 
42 #include "libmesh/dof_map.h"
43 #include "libmesh/linear_solver.h"
44 #include "libmesh/equation_systems.h"
45 #include "libmesh/linear_implicit_system.h"
46 #include "libmesh/periodic_boundary.h"
47 #include "libmesh/sparse_matrix.h"
48 #include "libmesh/numeric_vector.h"
49 #include "libmesh/slepc_macro.h"
50 #include "libmesh/perf_log.h"
51 
52 // User defined includes
53 #include "point_particle.h"
54 #include "particle_mesh.h"
55 #include "point_mesh.h"
56 #include "pm_system_stokes.h"
57 #include "brownian_system.h"
58 #include "pm_periodic_boundary.h"
59 #include "chebyshev.h"
60 #include "pm_toolbox.h"
61 #include "polymer_chain.h"
62 #include "random_generator.h"
63 #include "stokes_solver.h"
64 #include "ggem_system.h"
65 #include "copss_init.h"
66 #include "fix/fix_factory.h"
67 #include "fix/fix.h"
68 
69 
70 
75 // Bring in everything from the libMesh namespace
76 
77 
78 namespace libMesh{
79 
80 class Copss
81 {
82 public:
83  // PETSC MPI communicator
84  Parallel::Communicator *comm_in;
85  // error message string
86  std::string error_msg;
87  // output message string
88  std::string output_msg;
89  // control file object
90  GetPot input_file;
91  // control file name
92  std::string control_fileName;
93  // test name
94  std::string test_name;
95  bool print_info;
96  // physical parameters
97  const Real kB = 1.380662E-17;//1.380662E-23(J/K) = 1.3806623E-23(N*m/K) = 1.380662E-17(N*um/K)
98  const Real PI = libMesh::pi;
99  Real T; // simulation temperature (K)
100  Real kBT;// (N*um)
101  Real viscosity; // viscosity of the fluid (cp = N*s/um^2)
102  Real Rb; // radius of the bead
103  Real drag_c; // Drag coefficient (N*s/um)
104  Real Db;
105  std::string particle_type;
106 
107  // characteristic variables
108  Real tc; // characteristic time (diffusion time) (s)
109  Real uc; // characteristic velocity (um/s)
110  Real fc; // characteristic force (N)
111  Real muc; // non-dimension viscosity
112 
113  // Geometry information
114  unsigned int dim; // dimension of the box
115  std::string wall_type; // wall_type (slit or sphere)
116  std::vector<Real> wall_params; // (wall parameters; e.g. slit = '-50,50,-50,50,-50,50' or sphere = '10')
117  std::vector<bool> periodicity; // periodicity of the box
118  std::vector<bool> inlet; // inlet direction of the box
119  std::vector<Real> inlet_pressure; // inlet pressure
120  std::vector<bool> shear; // apply shear or not on boundary pairs
121  std::vector<Real> shear_rate; // shear rate on boundary pairs
122  std::vector<unsigned int> shear_direction; // shear direction on boundary pairs
123 
124  // Mesh information
125  bool generate_mesh; // flag to generate mesh or load mesh
126  std::string domain_mesh_file; // domain mesh filename
127  std::vector<unsigned int> n_mesh; // mesh size in all directions
128 
129  // Fix
130  std::vector<Fix*> fixes;
132  unsigned int numForceTypes;
133  std::vector<std::string> forceTypes;
134  std::vector<Fix::type_force> forces;
135  // map force_type to Fix Pointers
136 
137 
138  // GGEM information
139  Real alpha;
140 
141  // Solver information
149  std::string schur_pc_type;
150  std::string stokes_solver_type;
151  StokesSolverType solver_type;
152 
153  // Chebyshev information
154  unsigned int max_n_cheb; // max order of Chebyshev polynomianl
155  Real tol_cheb; // tolerance of chebyshev convergence
156  Real eig_factor; // factor to resize eigen value range
157  Real tol_eigen; // tolerance of eigenvalue convergence
158  bool compute_eigen; // if compute eigen value; false by default
159  bool read_eigen; // if read eigen value from existed file; false by default
160  // Run time info
161  bool with_hi;
162  bool with_brownian; // if consider brownian motion
163  std::size_t random_seed;
164  bool adaptive_dt; // if use adaptive time step (essential for brownian systems)
165  std::vector<Real> max_dr_coeff; // max displacement per step
166  Real max_dr;
167  bool restart; // if restart
168  std::size_t restart_step; // restart step
169  unsigned int nstep; // totol number of steps to run
170  unsigned int n_relax_step; // relaxation steps when Chebyshev cannot converge even after recompute eigenvalue
172  // ouput file
173  unsigned int write_interval; // output file write interval
174  std::vector<std::string> output_file;
175  // mesh
176  SerialMesh* mesh;
178  //std::unique_ptr<SerialMesh> mesh;
181 
182  //periodic boundary
184  //std::unique_ptr<PMPeriodicBoundary> pm_periodic_boundary;
185 
186  // equation system
187  unsigned int u_var, v_var, w_var, p_var;
188 
189  //integrate
190  // paramters for dynamic process;
192  unsigned int NP;
193  unsigned int n_vec;
194  Real hminf, hmaxf; // fluid mesh minimum
195  Real hmin, hmax; // all mesh minimum
196  bool cheb_converge = false;
197  unsigned int n_chebyshev_failure = 0;
198  Real eig_min = 0, eig_max = 0;
199  const std::string out_system_filename = "output_pm_system.e";
200  UniquePtr<NumericVector<Real>> v0_ptr;
201  ExodusII_IO* exodus_ptr;
202 
203  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
204  Create vectors and Shell Mat for use:
205  U0: particle velocity vector;
206  R0/R_mid: particle position vector;
207  dw/dw_mid: random vector;
208  RIN/ROUT: the initial and intermediate particle postion vector for msd output
209  RIN will not change, and ROUT excludes pbc
210  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
211  Vec U0, R0, R_mid, RIN,ROUT, dw, dw_mid;
212  PetscViewer viewer;
213  Mat M;
214  PetscRandom rand_ctx;
215  PetscScalar coef = 0.0;
217  std::vector<Point> center0;
218 
219  //variables in integrator
220  unsigned int istart;
221  unsigned int o_step;
222  Real real_time; // real time
224  unsigned int neighbor_list_update_interval = 0; // how often to update neighbor list
225  unsigned int timestep_duration; // how many steps elapsed since last neighbor_list update
227  std::vector<Real> vel0;
228  std::vector<Real> vel1;
229 
230 
231 
232 
233 
234 
235 
239  Copss(CopssInit& init);
240 
244  ~Copss();
245 
253  int check_libmesh();
254 
258  void start_time(struct tm * timeinfo);
259 
263  void end_time(struct tm * timeinfo);
264 
271  EquationSystems init_system(std::string input_file); // including the following 10 steps
272 
285  void read_input();
286 
287 
296  virtual void create_object_mesh() = 0;
297 
309  EquationSystems create_equation_systems();
310 
315  virtual void run(EquationSystems& equation_systems) = 0;
316 
317 
321  void destroy();
322 
323 
324 protected:
329  void read_system_info();
330  void read_physical_info();
331  virtual void read_particle_info() = 0;
332  void read_domain_info();
333  void read_force_info();
334  virtual void read_ggem_info() = 0;
336  void read_chebyshev_info();
337  void read_run_info();
338  void read_restart_time();
340 
344  void create_domain_mesh();
346  virtual void create_object() = 0;
347 
351  virtual void attach_object_mesh(PMLinearImplicitSystem& system) = 0;
353  virtual void set_parameters(EquationSystems& equation_systems) = 0;
354 
355  // force field
356  void attach_fixes(PMLinearImplicitSystem& system);
357 
365  void solve_undisturbed_system(EquationSystems& equation_systems);
366 
371  void create_brownian_system(EquationSystems& equation_systems);
372 
376  void fixman_integrate(EquationSystems& equation_systems, unsigned int& i);
377 
381  void langevin_integrate(EquationSystems& equation_systems, unsigned int& i);
382 
383  // update object positions due to PBS
384  virtual void update_object() {};
385  virtual void write_object(unsigned int step_id) = 0;
386 
387  // output precision
388  const int o_precision = 6;
389 };
390 
391 } // end namespace libMesh
Definition: copss_init.h:32
unsigned int nstep
Definition: copss.h:169
std::vector< Fix * > fixes
Definition: copss.h:130
Real eig_max
Definition: copss.h:198
virtual void update_object()
Definition: copss.h:384
void attach_fixes(PMLinearImplicitSystem &system)
Definition: copss.C:669
void read_input()
Definition: copss.C:93
Real Rb
Definition: copss.h:102
void destroy()
Definition: copss.C:1329
void langevin_integrate(EquationSystems &equation_systems, unsigned int &i)
Definition: copss.C:1182
bool read_eigen
Definition: copss.h:159
UniquePtr< NumericVector< Real > > v0_ptr
Definition: copss.h:200
std::size_t random_seed
Definition: copss.h:163
PetscRandom rand_ctx
Definition: copss.h:214
bool adaptive_dt
Definition: copss.h:164
void create_periodic_boundary()
Definition: copss.C:581
unsigned int n_chebyshev_failure
Definition: copss.h:197
Definition: fix_factory.h:22
unsigned int w_var
Definition: copss.h:187
unsigned int neighbor_list_update_interval
Definition: copss.h:224
std::string stokes_solver_type
Definition: copss.h:150
Vec U0
Definition: copss.h:211
unsigned int dim
Definition: copss.h:114
Real max_mesh_size
Definition: copss.h:179
std::vector< Real > vel0
Definition: copss.h:227
std::string error_msg
Definition: copss.h:86
Real tc
Definition: copss.h:108
void read_physical_info()
Definition: copss.C:122
std::string schur_pc_type
Definition: copss.h:149
GetPot input_file
Definition: copss.h:90
Vec ROUT
Definition: copss.h:211
bool update_neighbor_list_everyStep
Definition: copss.h:223
unsigned int max_n_cheb
Definition: copss.h:154
Real alpha
Definition: copss.h:139
void read_restart_time()
Definition: copss.C:443
Vec R0
Definition: copss.h:211
Vec dw
Definition: copss.h:211
Vec R_mid
Definition: copss.h:211
std::vector< bool > inlet
Definition: copss.h:118
void read_chebyshev_info()
Definition: copss.C:334
bool cheb_converge
Definition: copss.h:196
const Real kB
Definition: copss.h:97
Real hminf
Definition: copss.h:194
std::vector< Fix::type_force > forces
Definition: copss.h:134
void create_brownian_system(EquationSystems &equation_systems)
Definition: copss.C:819
int check_libmesh()
Definition: copss.C:39
Real muc
Definition: copss.h:111
unsigned int p_var
Definition: copss.h:187
Definition: brownian_system.h:58
virtual void attach_object_mesh(PMLinearImplicitSystem &system)=0
Definition: pm_periodic_boundary.h:46
unsigned int u_var
Definition: copss.h:187
Real hmin
Definition: copss.h:195
std::vector< std::string > output_file
Definition: copss.h:174
Copss(CopssInit &init)
Definition: copss.C:27
Definition: copss.h:80
SerialMesh * mesh
Definition: copss.h:176
virtual void create_object()=0
bool print_info
Definition: copss.h:95
int max_linear_iterations
Definition: copss.h:142
bool compute_eigen
Definition: copss.h:158
std::vector< Real > inlet_pressure
Definition: copss.h:119
StokesSolverType solver_type
Definition: copss.h:151
Real viscosity
Definition: copss.h:101
Real T
Definition: copss.h:99
bool with_hi
Definition: copss.h:161
void create_domain_mesh()
Definition: copss.C:496
Real eig_min
Definition: copss.h:198
unsigned int write_interval
Definition: copss.h:173
Real tol_cheb
Definition: copss.h:155
unsigned int NP
Definition: copss.h:192
Real search_radius_e
Definition: copss.h:180
Real max_dr
Definition: copss.h:166
const int o_precision
Definition: copss.h:388
std::vector< bool > periodicity
Definition: copss.h:117
bool generate_mesh
Definition: copss.h:125
Vec dw_mid
Definition: copss.h:211
void read_restart_eigenvalue()
Definition: copss.C:469
void fixman_integrate(EquationSystems &equation_systems, unsigned int &i)
Definition: copss.C:859
PetscScalar coef
Definition: copss.h:215
PMPeriodicBoundary * pm_periodic_boundary
Definition: copss.h:183
virtual void read_ggem_info()=0
unsigned int numForceTypes
Definition: copss.h:132
ExodusII_IO * exodus_ptr
Definition: copss.h:201
Real tol_eigen
Definition: copss.h:157
void read_force_info()
Definition: copss.C:260
Real eig_factor
Definition: copss.h:156
void attach_period_boundary(PMLinearImplicitSystem &system)
Definition: copss.C:683
Real schur_user_ksp_atol
Definition: copss.h:148
std::vector< unsigned int > shear_direction
Definition: copss.h:122
std::vector< Real > shear_rate
Definition: copss.h:121
std::vector< bool > shear
Definition: copss.h:120
void read_stokes_solver_info()
Definition: copss.C:294
unsigned int n_vec
Definition: copss.h:193
virtual void create_object_mesh()=0
Real linear_solver_rtol
Definition: copss.h:143
bool debug_info
Definition: copss.h:171
std::string control_fileName
Definition: copss.h:92
void read_domain_info()
Definition: copss.C:158
std::vector< unsigned int > n_mesh
Definition: copss.h:127
void read_run_info()
Definition: copss.C:369
Parallel::Communicator * comm_in
Definition: copss.h:84
bool user_defined_pc
Definition: copss.h:145
EquationSystems create_equation_systems()
Definition: copss.C:611
Real schur_user_ksp_rtol
Definition: copss.h:147
PetscViewer viewer
Definition: copss.h:212
std::vector< Point > center0
Definition: copss.h:217
Real hmaxf
Definition: copss.h:194
Definition: pm_linear_implicit_system.h:52
Real linear_solver_atol
Definition: copss.h:144
virtual void write_object(unsigned int step_id)=0
std::vector< Real > max_dr_coeff
Definition: copss.h:165
void read_system_info()
Definition: copss.C:109
Real search_radius_p
Definition: copss.h:180
const Real PI
Definition: copss.h:98
Real min_mesh_size
Definition: copss.h:179
virtual void run(EquationSystems &equation_systems)=0
std::string wall_type
Definition: copss.h:115
std::vector< Real > vel1
Definition: copss.h:228
bool restart
Definition: copss.h:167
bool reinit_stokes
Definition: copss.h:191
Real kBT
Definition: copss.h:100
Vec RIN
Definition: copss.h:211
BrownianSystem * brownian_sys
Definition: copss.h:216
virtual void read_particle_info()=0
EquationSystems init_system(std::string input_file)
Definition: copss.C:82
unsigned int istart
Definition: copss.h:220
Real fc
Definition: copss.h:110
FixFactory * fix_factory
Definition: copss.h:131
std::string test_name
Definition: copss.h:94
Real Db
Definition: copss.h:104
unsigned int n_relax_step
Definition: copss.h:170
std::string domain_mesh_file
Definition: copss.h:126
~Copss()
Definition: copss.C:34
Real real_time
Definition: copss.h:222
unsigned int o_step
Definition: copss.h:221
PointMesh< 3 > * point_mesh
Definition: copss.h:177
bool schur_user_ksp
Definition: copss.h:146
virtual void set_parameters(EquationSystems &equation_systems)=0
bool neighbor_list_update_flag
Definition: copss.h:226
Real drag_c
Definition: copss.h:103
unsigned int v_var
Definition: copss.h:187
bool with_brownian
Definition: copss.h:162
std::size_t restart_step
Definition: copss.h:168
std::vector< std::string > forceTypes
Definition: copss.h:133
void end_time(struct tm *timeinfo)
Definition: copss.C:74
Mat M
Definition: copss.h:213
void start_time(struct tm *timeinfo)
Definition: copss.C:65
std::string particle_type
Definition: copss.h:105
unsigned int timestep_duration
Definition: copss.h:225
void solve_undisturbed_system(EquationSystems &equation_systems)
Definition: copss.C:787
Real hmax
Definition: copss.h:195
const std::string out_system_filename
Definition: copss.h:199
Real uc
Definition: copss.h:109
std::string output_msg
Definition: copss.h:88
Definition: brownian_system.h:72
std::vector< Real > wall_params
Definition: copss.h:116