Revision 93, 1.1 kB
(checked in by gruber, 5 months ago)
|
3.2.0 commit. Added node number subscripting. Fixed anisotropic grain growth (phase field, sparsePF) codes. Added anisotropic Zener pinning codes. Added comments to example codes. Changed example codes to use vector- and node number-based subscripting. Fixed memory problem with sparse data structure.
|
Line | |
---|
1 | |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | #ifndef ALLENCAHN_UPDATE |
---|
6 | #define ALLENCAHN_UPDATE |
---|
7 | #include"MMSP.hpp" |
---|
8 | #include<cmath> |
---|
9 | |
---|
10 | namespace MMSP{ |
---|
11 | |
---|
12 | void generate(int dim, const char* filename) |
---|
13 | { |
---|
14 | if (dim==2) { |
---|
15 | MMSP::grid<2,double> grid(1,0,128,0,128); |
---|
16 | |
---|
17 | for (int i=0; i<nodes(grid); i++) |
---|
18 | grid(i) = 1.0-2.0*double(rand())/double(RAND_MAX); |
---|
19 | |
---|
20 | output(grid,filename); |
---|
21 | } |
---|
22 | |
---|
23 | if (dim==3) { |
---|
24 | MMSP::grid<3,double> grid(1,0,64,0,64,0,64); |
---|
25 | |
---|
26 | for (int i=0; i<nodes(grid); i++) |
---|
27 | grid(i) = 1.0-2.0*double(rand())/double(RAND_MAX); |
---|
28 | |
---|
29 | MMSP::output(grid,filename); |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | template <int dim, typename T> void update(MMSP::grid<dim,T>& grid, int steps) |
---|
34 | { |
---|
35 | MMSP::grid<dim,T> update(grid); |
---|
36 | |
---|
37 | double r = 1.0; |
---|
38 | double u = 1.0; |
---|
39 | double K = 1.0; |
---|
40 | double M = 1.0; |
---|
41 | double dt = 0.01; |
---|
42 | |
---|
43 | for (int step=0; step<steps; step++) { |
---|
44 | for (int i=0; i<nodes(grid); i++) { |
---|
45 | double phi = grid(i); |
---|
46 | update(i) = phi-dt*M*(-r*phi+u*pow(phi,3)-K*laplacian(grid,i)); |
---|
47 | } |
---|
48 | swap(grid,update); |
---|
49 | ghostswap(grid); |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | #endif |
---|