-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathobj_field.hh
More file actions
137 lines (131 loc) · 5.42 KB
/
obj_field.hh
File metadata and controls
137 lines (131 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef OBJ_FIELD_HH
#define OBJ_FIELD_HH
#define _USE_MATH_DEFINES
#include <cmath>
#include "int_box.hh"
#include "fields.hh"
#include "object.hh"
#include "level++.hh"
class fluid_2d;
/** \brief A structure containing material constants for a solid. */
struct mat_const {
/** The shear modulus. */
double G;
/** The solid density. */
double rhos;
/** The multiplier to apply to the extra viscosity in the transition
* region. */
double ev_trans_mult;
/** Whether the solid is initialized to its own velocity, or inherits it
* from the fluid. */
bool set_velocity;
mat_const(double G_,double rhos_,double ev_trans_mult_,bool set_velocity_=true)
: G(G_), rhos(rhos_), ev_trans_mult(ev_trans_mult_),
set_velocity(set_velocity_) {}
};
/** \brief A class describing all data needed to simulate a single solid. */
class obj_field {
public:
/** The number of fields to extrapolate, set to two for the two
* components of the reference map. */
static const int c=2;
/** The memory step length, taking into account ghost point allocation. */
const int ml;
/** The vertical grid size, taking into account ghost point allocation. */
const int nl;
/** The total number of grid points, including ghost regions. */
const int mem;
/** The shear modulus. */
const double G;
/** The solid density. */
const double rhos;
/** The multiplier to apply to the extra viscosity in the transition
* region. */
const double ev_trans_mult;
/** The transition width. */
const double eps;
/** The level set pinning width. */
const double pinw;
/** Whether the solid is initialized to its own velocity, or inherits it
* from the fluid. */
const bool set_velocity;
/** An array containing the solid fields. */
s_field* const sbase;
/** A pointer to the (0,0) grid cell in the solid field array. */
s_field* const sm;
/** A class for representing the solid interface using a level set. */
levelset ls;
/** A pointer to the phi array held within the levelset class. */
double* const phi_base;
/** A pointer to the (0,0) grid cell in the phi array. */
double* const phi;
/** A pointer to the indicator field array within the levelset class. */
int* const cbase;
/** A pointer to the (0,0) grid cell in the levelset indicator field. */
int* const cc;
/** A pointer to the object class containing details about the object's
* geometry and other attributes. */
object* obj;
/** The extra viscosity to apply in the solid. */
double ex_visc;
obj_field(fluid_2d &f,object* obj_,mat_const mc);
void set_ex_visc(double tfac,double &sws_max,double &ex_visc_max,double &rhos_div_ev_min);
/** The class destructor frees the dynamically allocated memory. */
~obj_field() {
delete [] sbase;
}
inline void acc(int ij,double *p,double w,double x,double y) {
s_field &s=sbase[ij];
*p+=w*s.nX;p[1]+=w*x*s.nX;p[2]+=w*y*s.nX;
p[3]+=w*s.nY;p[4]+=w*x*s.nY;p[5]+=w*y*s.nY;
}
inline void set(int ij,double *p,double al,double be,double ga) {
sbase[ij].nX=*p*al+p[1]*be+p[2]*ga;
sbase[ij].nY=p[3]*al+p[4]*be+p[5]*ga;
}
/** Extrapolates the reference map from inside the solid to the
* neighboring grid points. */
inline void extrapolate() {
ls.extrapolate_fields(*this);
}
inline double coll_func(double x) {
return x>eps?0:0.5-x*tf1;
}
/** Calculates the smoothed Heaviside transition function.
* \param[in] x the function argument.
* \return The function value. */
inline double trans_func(double x) {
return x>eps?0:trans_func_in(x);
}
/** Calculates the smoothed Heaviside transition function, assuming
* that the given argument corresponds to being inside the solid or the
* blur zone.
* \param[in] x the function argument.
* \return The function value. */
inline double trans_func_in(double x) {
return x<-eps?1:0.5-x*tf1-tf2*sin(tf3*x);
}
/** Calculates the derivative of the smoothed Heaviside transition
* function multiplied by epsilon, assuming that the given argument
* corresponds to being inside the solid or the blur zone.
* \param[in] x the function argument.
* \return The function value. */
inline double tderiv_func_in(double x) {
return x<-eps?0:0.5*(1+cos(M_PI*x/eps));
}
void pin();
/** Initializes the reference map and level set values at a grid point
* \param[in] ij the grid point index.
* \param[in] (x,y) the position of this grid point. */
void init(int ij,double x,double y) {
obj->transform(x,y,sm[ij].X,sm[ij].Y);
phi[ij]=obj->phi(sm[ij].X,sm[ij].Y);
}
void bound(int_box &ib);
void mom_contrib(int ij,double &mu,double &mv,double &rho,double &sfrac);
void rho_contrib(int ij,double &rho,double &sfrac);
private:
/** Constants that appear in the transition function calculations. */
const double tf1,tf2,tf3;
};
#endif