-
Notifications
You must be signed in to change notification settings - Fork 15
/
ic.cxx
233 lines (200 loc) · 7.37 KB
/
ic.cxx
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <iostream>
#include "constants.hpp"
#include "parameters.hpp"
#include "matprops.hpp"
#include "ic-read-temp.hpp"
#include "ic.hpp"
namespace {
class Zone
{
public:
virtual ~Zone() {};
virtual bool contains(const double x[NDIMS]) const = 0;
};
class Empty_zone : public Zone
{
public:
bool contains(const double x[NDIMS]) const {return false;}
};
class Planar_zone : public Zone
{
private:
const double az, incl;
const double halfwidth; // in meter
#ifdef THREED
const double ymin, ymax; // in meter
#endif
const double zmin, zmax; // in meter
const double *x0;
public:
Planar_zone(const double center[NDIMS], double azimuth, double inclination, double halfwidth_,
#ifdef THREED
double ymin_, double ymax_,
#endif
double zmin_, double zmax_) :
az(std::tan(azimuth * DEG2RAD)), incl(1/std::tan(inclination * DEG2RAD)), halfwidth(halfwidth_),
#ifdef THREED
ymin(ymin_), ymax(ymax_),
#endif
zmin(zmin_), zmax(zmax_),
x0(center) // Copy the pointer only, not the data. The caller needs to keep center alive.
{}
bool contains(const double x[NDIMS]) const
{
// Is x within halfwidth distance to a plane cutting through x0?
return (x[NDIMS-1] > zmin &&
x[NDIMS-1] < zmax &&
#ifdef THREED
x[1] > ymin &&
x[1] < ymax &&
#endif
std::fabs( (x[0] - x0[0])
#ifdef THREED
- az * (x[1] - x0[1])
#endif
+ incl * (x[NDIMS-1] - x0[NDIMS-1]) ) < halfwidth );
}
};
class Ellipsoidal_zone : public Zone
{
private:
const double *x0;
double semi_axis2[NDIMS];
public:
Ellipsoidal_zone(const double center[NDIMS], const double semi_axis[NDIMS]) :
x0(center) // Copy the pointer only, not the data. The caller needs to keep center alive.
{
for(int i=0; i<NDIMS; i++)
semi_axis2[i] = semi_axis[i] * semi_axis[i];
}
bool contains(const double x[NDIMS]) const
{
return ( (x[0] - x0[0])*(x[0] - x0[0])/semi_axis2[0]
#ifdef THREED
+ (x[1] - x0[1])*(x[1] - x0[1])/semi_axis2[1]
#endif
+ (x[NDIMS-1] - x0[NDIMS-1])*(x[NDIMS-1] - x0[NDIMS-1])/semi_axis2[NDIMS-1] < 1 );
}
};
} // anonymous namespace
void initial_stress_state(const Param ¶m, const Variables &var,
tensor_t &stress, double_vec &stressyy, tensor_t &strain,
double &compensation_pressure)
{
if (param.control.gravity == 0) {
compensation_pressure = 0;
return;
}
// lithostatic condition for stress and strain
double rho = var.mat->rho(0);
double ks = var.mat->bulkm(0);
for (int e=0; e<var.nelem; ++e) {
const int *conn = (*var.connectivity)[e];
double zcenter = 0;
for (int i=0; i<NODES_PER_ELEM; ++i) {
zcenter += (*var.coord)[conn[i]][NDIMS-1];
}
zcenter /= NODES_PER_ELEM;
double p = ref_pressure(param, zcenter);
if (param.control.ref_pressure_option == 1 ||
param.control.ref_pressure_option == 2) {
ks = var.mat->bulkm(e);
}
for (int i=0; i<NDIMS; ++i) {
stress[e][i] = -p;
strain[e][i] = -p / ks / NDIMS;
}
if (param.mat.is_plane_strain)
stressyy[e] = -p;
}
compensation_pressure = ref_pressure(param, -param.mesh.zlength);
}
void initial_weak_zone(const Param ¶m, const Variables &var,
double_vec &plstrain)
{
Zone *weakzone;
// TODO: adding different types of weak zone
double plane_center[NDIMS]; // this variable must outlive weakzone
switch (param.ic.weakzone_option) {
case 0:
weakzone = new Empty_zone();
break;
case 1:
// a planar weak zone, cut through top center
plane_center[0] = param.ic.weakzone_xcenter * param.mesh.xlength;
#ifdef THREED
plane_center[1] = param.ic.weakzone_ycenter * param.mesh.ylength;
#endif
plane_center[NDIMS-1] = -param.ic.weakzone_zcenter * param.mesh.zlength;
weakzone = new Planar_zone(plane_center,
param.ic.weakzone_azimuth,
param.ic.weakzone_inclination,
param.ic.weakzone_halfwidth * param.mesh.resolution,
#ifdef THREED
param.ic.weakzone_y_min * param.mesh.ylength,
param.ic.weakzone_y_max * param.mesh.ylength,
#endif
-param.ic.weakzone_depth_max * param.mesh.zlength,
-param.ic.weakzone_depth_min * param.mesh.zlength);
break;
case 2:
// a ellipsoidal weak zone
double semi_axis[NDIMS];
plane_center[0] = param.ic.weakzone_xcenter * param.mesh.xlength;
semi_axis[0] = param.ic.weakzone_xsemi_axis;
#ifdef THREED
plane_center[1] = param.ic.weakzone_ycenter * param.mesh.ylength;
semi_axis[1] = param.ic.weakzone_ysemi_axis;
#endif
plane_center[NDIMS-1] = -param.ic.weakzone_zcenter * param.mesh.zlength;
semi_axis[NDIMS-1] = param.ic.weakzone_zsemi_axis;
weakzone = new Ellipsoidal_zone(plane_center, semi_axis);
break;
default:
std::cerr << "Error: unknown weakzone_option: " << param.ic.weakzone_option << '\n';
std::exit(1);
}
for (int e=0; e<var.nelem; ++e) {
const int *conn = (*var.connectivity)[e];
// the coordinate of the center of this element
double center[NDIMS] = {0};
for (int i=0; i<NODES_PER_ELEM; ++i) {
for (int d=0; d<NDIMS; ++d) {
center[d] += (*var.coord)[conn[i]][d];
}
}
for (int d=0; d<NDIMS; ++d) {
center[d] /= NODES_PER_ELEM;
}
if (weakzone->contains(center))
plstrain[e] = param.ic.weakzone_plstrain;
// Find the most abundant marker mattype in this element
// int_vec &a = (*var.elemmarkers)[e];
// int material = std::distance(a.begin(), std::max_element(a.begin(), a.end()));
}
delete weakzone;
}
void initial_temperature(const Param ¶m, const Variables &var,
double_vec &temperature)
{
switch(param.ic.temperature_option) {
case 0:
{
const double age = param.ic.oceanic_plate_age_in_yr * YEAR2SEC;
const MatProps &mat = *var.mat;
const double diffusivity = mat.k(0) / mat.rho(0) / mat.cp(0); // thermal diffusivity of 0th element
for (int i=0; i<var.nnode; ++i) {
double w = -(*var.coord)[i][NDIMS-1] / std::sqrt(4 * diffusivity * age);
temperature[i] = param.bc.surface_temperature +
(param.bc.mantle_temperature - param.bc.surface_temperature) * std::erf(w);
}
break;
}
case 90:
read_external_temperature_from_comsol(param, var, *var.temperature);
break;
default:
std::cout << "Error: unknown ic.temperature option: " << param.ic.temperature_option << '\n';
std::exit(1);
}
}