Free Electron
SemiImplicit2D.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_SemiImplicit2D_h__
8 #define __solve_SemiImplicit2D_h__
9 
10 #include "signal/signal.h"
11 #include "datatool/datatool.h"
12 #include "shape/shape.h"
13 
14 #define PARTICLE_DEBUG
15 
16 namespace fe
17 {
18 namespace ext
19 {
20 
21 
22 /** Semi Implicit time integration
23 
24  @copydoc SemiImplicit2D_info
25  */
26 class FE_DL_EXPORT SemiImplicit2D : public Handled<SemiImplicit2D>
27 {
28  public:
29  SemiImplicit2D(void);
30 virtual ~SemiImplicit2D(void);
31 
32 virtual void compile(sp<RecordGroup> rg_input);
33 virtual void initialize(sp<Scope> a_spScope);
34 virtual void extract(sp<RecordGroup> rg_output);
35 virtual void prestep(bool a_force_only);
36 virtual void step(t_solve_real a_timestep, t_solve_v2 &a_totalConstraintForce);
37 
38 virtual bool isForceOnly(void) { return m_force_only; }
39 
40 virtual void setRayleighDamping(bool a_flag) { m_rayleigh_damping = a_flag; }
41 virtual void setRayleighDamping(t_solve_real a_stiffness, t_solve_real a_mass)
42  {
43  m_rayleigh_stiffness = a_stiffness;
44  m_rayleigh_mass = -a_mass;
45  }
46 
47  class Particle
48  {
49  public:
50  t_solve_v2 m_location;
51  t_solve_v2 m_estimated;
52  t_solve_v2 m_velocity;
53  t_solve_v2 m_force;
54  t_solve_v2 m_force_weak;
55  t_solve_v2 m_force_external;
56  t_solve_real m_mass;
57  t_solve_v2 m_prev_location;
58  t_solve_v2 m_prev_velocity;
59  t_solve_v2 m_constraint_force;
60 #ifdef PARTICLE_DEBUG
61  Color m_color;
62 #endif
63  };
64 
65  std::vector<Particle> &particles(void) { return m_particles; }
66  bool lookupIndex(unsigned int &a_particle, Record &r_particle);
67 
68  class FE_DL_EXPORT CompileMatrix
69  {
70  public:
71  CompileMatrix(void);
72  ~CompileMatrix(void);
73 
74  typedef t_solve_m2 **t_ppBlock;
75  typedef std::vector<t_ppBlock> t_dfdx_array;
76  typedef std::vector<t_ppBlock> t_dfdv_array;
77  typedef std::pair<t_dfdx_array, t_dfdv_array> t_entry;
78  typedef std::map<unsigned int, t_entry> t_row;
79 
80  std::vector<t_row> m_rows;
81 
82  void clear(void);
83  void setRows(unsigned int a_count);
84  unsigned int rows(void);
85  t_row &row(unsigned int a_index);
86  t_entry &entry( unsigned int a_i,
87  unsigned int a_j);
88 
89  typedef std::set<unsigned int> t_nonzero_set;
90  typedef std::vector< t_nonzero_set > t_nonzero_pattern;
91 
92  void symbolicFill(void);
93  };
94 
95  //typedef std::size_t t_size;
96  typedef unsigned int t_size;
97  typedef std::pair<t_size, t_size> t_pair;
98  typedef std::vector<t_pair> t_pairs;
99  class Force : public Counted
100  {
101  public:
102  Force(void){}
103  virtual ~Force(void){}
104 
105  virtual void clear(void){}
106  virtual void accumulate(void){}
107  virtual bool validate(void){ return true; }
108 
109  virtual void compile( sp<RecordGroup> rg_input,
110  std::vector<Particle> &a_particles,
111  CompileMatrix &a_compileMatrix){}
112  virtual void precompile(sp<RecordGroup> rg_input) {}
113  virtual void pairs( sp<RecordGroup> rg_input,
114  t_pairs &a_pairs) {}
115  };
116 
117 virtual void addForce(sp<Force> a_force, bool a_add_damping=false);
118 
119 
120 
121  private:
122 
123  void reorder(std::vector<unsigned int> &a_order, t_pairs &a_pairs);
124 
125  std::vector<Particle> m_particles;
126 
127  AsParticle m_asParticle;
128  AsSolverParticle m_asSolverParticle;
129  AsLineConstrained m_asLineConstrained;
130  AsPlaneConstrained m_asPlaneConstrained;
131  AsComponent m_asComponent;
132  AsForcePoint m_asForcePoint;
133  AsTemporal m_asTemporal;
134  AsValidate m_asValidate;
135  AsAccumulate m_asAccumulate;
136  AsClear m_asClear;
137  AsUpdate m_asUpdate;
138 #ifdef PARTICLE_DEBUG
139  AsColored m_asColored;
140 #endif
141  AsForceFilter m_asForceFilter;
142  hp<SignalerI> m_hpSignaler;
143 
144  unsigned int m_n;
145  unsigned int m_n_sim;
146  std::vector< sp<Force> > m_forces_add_damping;
147  std::vector< sp<Force> > m_forces_as_is;
148 
149  t_solve_m2 m_dummy_block;
150 
155 
156  std::vector<t_solve_v2> m_rhs;
157  std::vector<t_solve_v2> m_dv;
158  std::vector<t_solve_v2> m_tmp;
159 
160  std::map<FE_UWORD, unsigned int> m_recordToParticle;
161 
162  t_solve_real m_dv2dxRatio;
163  t_solve_real m_dxImplicitness;
164  t_solve_real m_dvImplicitness;
165 
166  t_solve_real m_ratio;
167  unsigned int m_subdivcnt;
168  unsigned int m_subdivsz;
169  t_solve_real m_subdivmult;
170 
171  bool m_rayleigh_damping;
172  t_solve_real m_rayleigh_stiffness;
173  t_solve_real m_rayleigh_mass;
174  std::vector<t_solve_v2> m_perturb;
175 
176  bool m_force_only;
177 };
178 
179 } /* namespace */
180 } /* namespace */
181 
182 
183 #endif /* __solve_SemiImplicit2D_h__ */
184 
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
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
Semi Implicit time integration.
Definition: SemiImplicit2D.h:26
accumulate signal
Definition: solveAS.h:59