Free Electron
SemiImplicit.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __solve_SemiImplicit_h__
8 #define __solve_SemiImplicit_h__
9 
10 #include "signal/signal.h"
11 #include "datatool/datatool.h"
12 #include "shape/shape.h"
13 
14 #define PARTICLE_DEBUG
15 //#define USE_FILTERS
16 
17 namespace fe
18 {
19 namespace ext
20 {
21 
22 typedef FE_UWORD FE_UWORD;
23 
24 
25 /** Semi Implicit time integration
26 
27  @copydoc SemiImplicit_info
28  */
29 class FE_DL_EXPORT SemiImplicit : public Handled<SemiImplicit>
30 {
31  public:
32  SemiImplicit(void);
33 virtual ~SemiImplicit(void);
34 
35 virtual void compile(sp<RecordGroup> rg_input);
36 virtual void initialize(sp<Scope> a_spScope);
37 virtual void extract(sp<RecordGroup> rg_output);
38 virtual void prestep(void);
39 virtual void step(t_solve_real a_timestep, t_solve_v3 &a_totalConstraintForce);
40 
41 virtual void setGravity(t_solve_v3 a_g) { m_gravity = a_g; }
42 virtual void setDirectSolve(bool a_flag) { m_direct_solve = a_flag; }
43 virtual void set2D(bool a_flag) { m_2D = a_flag; }
44 virtual void setRayleighDamping(bool a_flag) { m_rayleigh_damping = a_flag; }
45 virtual void setRayleighDamping(t_solve_real a_stiffness, t_solve_real a_mass)
46  {
47  m_rayleigh_stiffness = a_stiffness;
48  m_rayleigh_mass = -a_mass;
49  }
50 
51  class Particle
52  {
53  public:
54  t_solve_v3 m_location;
55  t_solve_v3 m_estimated;
56  t_solve_v3 m_velocity;
57  t_solve_v3 m_force;
58  t_solve_v3 m_force_weak;
59  t_solve_v3 m_force_external;
60  t_solve_real m_mass;
61  t_solve_v3 m_prev_location;
62  t_solve_v3 m_prev_velocity;
63  t_solve_v3 m_constraint_force;
64 #ifdef PARTICLE_DEBUG
65  Color m_color;
66 #endif
67  };
68 
69  std::vector<Particle> &particles(void) { return m_particles; }
70  bool lookupIndex(unsigned int &a_particle, Record &r_particle);
71 
72  class FE_DL_EXPORT CompileMatrix
73  {
74  public:
75  CompileMatrix(void);
76  ~CompileMatrix(void);
77 
78  typedef t_solve_matrix **t_ppBlock;
79  typedef std::vector<t_ppBlock> t_dfdx_array;
80  typedef std::vector<t_ppBlock> t_dfdv_array;
81  typedef std::pair<t_dfdx_array, t_dfdv_array> t_entry;
82  typedef std::map<unsigned int, t_entry> t_row;
83 
84  std::vector<t_row> m_rows;
85 
86  void clear(void);
87  void setRows(unsigned int a_count);
88  unsigned int rows(void);
89  t_row &row(unsigned int a_index);
90  t_entry &entry( unsigned int a_i,
91  unsigned int a_j);
92 
93  typedef std::set<unsigned int> t_nonzero_set;
94  typedef std::vector< t_nonzero_set > t_nonzero_pattern;
95 
96  void symbolicFill(void);
97  };
98 
99  //typedef std::size_t t_size;
100  typedef unsigned int t_size;
101  typedef std::pair<t_size, t_size> t_pair;
102  typedef std::vector<t_pair> t_pairs;
103  class Force : public Counted, public CastableAs<Force>
104  {
105  public:
106  Force(void){}
107  virtual ~Force(void){}
108 
109  virtual void clear(void){}
110  virtual void accumulate(void){}
111  virtual bool validate(void){ return true; }
112 
113  virtual void compile( sp<RecordGroup> rg_input,
114  std::vector<Particle> &a_particles,
115  CompileMatrix &a_compileMatrix){}
116  virtual void precompile(sp<RecordGroup> rg_input) {}
117  virtual void pairs( sp<RecordGroup> rg_input,
118  t_pairs &a_pairs) {}
119  virtual void constrain( std::vector< FilterConstraint<t_solve_real> > &a_filters,
120  std::vector<t_solve_v3> &a_dv,
121  std::vector<t_solve_v3> &a_dx,
122  t_solve_real a_dt){}
123  };
124 
125 virtual void addForce(sp<Force> a_force, bool a_add_damping=false);
126 
127 
128 
129  private:
130 
131  void reorder(std::vector<unsigned int> &a_order, t_pairs &a_pairs);
132 
133  std::vector<Particle> m_particles;
134 
135  AsParticle m_asParticle;
136  AsSolverParticle m_asSolverParticle;
137  AsLineConstrained m_asLineConstrained;
138  AsPlaneConstrained m_asPlaneConstrained;
139  AsComponent m_asComponent;
140  AsForcePoint m_asForcePoint;
141  AsTemporal m_asTemporal;
142  AsValidate m_asValidate;
143  AsAccumulate m_asAccumulate;
144  AsClear m_asClear;
145  AsUpdate m_asUpdate;
146 #ifdef PARTICLE_DEBUG
147  AsColored m_asColored;
148 #endif
149  AsForceFilter m_asForceFilter;
150  hp<SignalerI> m_hpSignaler;
151 
152  unsigned int m_n;
153  unsigned int m_n_sim;
154  std::vector< sp<Force> > m_forces_add_damping;
155  std::vector< sp<Force> > m_forces_as_is;
156 
157  t_solve_matrix m_dummy_block;
158 
162  sp< UpperTriangularBCRS<t_solve_real> > m_lhs_snapshot;
163 
164  std::vector<t_solve_v3> m_rhs;
165  std::vector<t_solve_v3> m_dv;
166  std::vector<t_solve_v3> m_tmp;
167 
168  t_solve_v3 m_gravity;
169 
170  std::map<FE_UWORD, unsigned int> m_recordToParticle;
171  //std::map<unsigned int, unsigned int> m_recordToParticle;
172 
173  BlockDiagonalPreconditioner<t_solve_real> m_preconditioner;
174  //OverlappedInversionPreconditioner m_preconditioner2;
175  BlockPCG<t_solve_real> m_solver;
176 
177  t_solve_real m_dv2dxRatio;
178  t_solve_real m_dxImplicitness;
179  t_solve_real m_dvImplicitness;
180 
181  t_solve_real m_ratio;
182  unsigned int m_subdivcnt;
183  unsigned int m_subdivsz;
184  t_solve_real m_subdivmult;
185 
186  bool m_direct_solve;
187  bool m_2D;
188 
189  bool m_rayleigh_damping;
190  t_solve_real m_rayleigh_stiffness;
191  t_solve_real m_rayleigh_mass;
192  std::vector<t_solve_v3> m_perturb;
193 #ifndef USE_FILTERS
194  std::vector<FilterConstraint< t_solve_real> > m_dummy_filters;
195 #endif
196 };
197 
198 } /* namespace */
199 } /* namespace */
200 
201 
202 #endif /* __solve_SemiImplicit_h__ */
203 
just a Component
Definition: AccessorSets.h:92
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
force application point
Definition: shapeAS.h:42
clear signal
Definition: solveAS.h:38
Special vector for color (RGBA)
Definition: Color.h:21
Semi Implicit time integration.
Definition: SemiImplicit.h:29
particle in physical space
Definition: shapeAS.h:58
Time-based Operator.
Definition: datatoolAS.h:73
validate signal
Definition: solveAS.h:80
update state signal
Definition: solveAS.h:97
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Base class providing an fe::Handle to the derived class.
Definition: Handled.h:209
accumulate signal
Definition: solveAS.h:59
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192