dune-composites (unstable)

defectGenerator.hh
1#include <random>
2#include "KLFunctions.hh"
3#include "general.hh"
4#include "readData.hh"
5
6#ifndef COEFF_HH
7#define COEFF_HH
8
9namespace Dune{
10 namespace Composites{
11
12 // Class which constructs
13 class COEFF
14 {
15 public:
16 // Constructor for COEFF class
17 COEFF(){
18 //: L(LengthX), N(numKLmodes), sigKL(sdRandomField), ellx(correlationLength)
19 L = 346;
20 N = 30;
21 ellx = 66.75;
22 freqx.resize(N); // std::vector<double> - contain N eigenfrequencies associate with N largest eigenvalues of covariance kernel
23 lam1Dx.resize(N); // std::vector<double> - contain N largest eigenvalues of covariance kernel
24 rootFinder(N,ellx,freqx); // Find eigenfrequencies
25 evaluate_eigenValues(ellx,lam1Dx,freqx); // Evaluates eigenvalues
26 xi.resize(N);
27 }
28
29
30 double inline evalPhi(double x, int i) const{
31 double phi = 0.0;
32 double omega;
33 // x *= 58 / 5; // to convert back to pixels from mm
34 double l = 0.0;
35 double LL = 0.0; // L in mm stored as LL
36 LL = L * 5.0 / 58.0;
37 l = ellx/L; // ellx is in pixels so its normalized by L in pixels
38
39 x /= LL; // x is normalized such that x \in [0,1]
40 omega = freqx[i];
41 double nm = std::sin(2.0*omega)*(0.25*(l*l*omega - 1.0/omega)) - (0.5 * l * std::cos(2.0 * omega)) + (0.5 * ( 1 + l + l*l*omega*omega));
42
43 double norm = 1.0 / std::sqrt(L * nm);
44
45 phi = norm * (std::sin(x * omega) + (l * omega * std::cos(x * omega)) );
46 return phi;
47 }
48
49 double inline getxi(int i) const{
50 return xi[i];
51 }
52
53
54 int inline getN() const{
55 return N;
56 }
57
58 double inline getFreq(int i) const{
59 return freqx[i];
60 }
61
62
63 double inline getLam1Dx(int i) const{
64 return lam1Dx[i];
65 }
66
67 // void inline user_random_field_normal()
68 // {
69 // std::random_device rd;
70 // std::mt19937 gen(rd());
71 // std::normal_distribution<double> randn(0.0,1.0);
72 // std::fill(xi.begin(), xi.end(), 0.0);
73 // for (int j = 0; j < N; j++){
74 // xi[j] = randn(gen);
75 // }
76
77 // } // end user_random_field
78
79 void inline user_random_field()
80 {
81 //Sample number TODO
82 int sn = 0; //sample number!
83 auto r = readData("RandomFieldCoefficient/coeffs.txt");
84 for (int i=0; i<N; i++){
85 xi[i] = r[sn][i];
86 }
87 } // end user_random_field
88
89
90 private:
91
92 int N;
93 double L, ellx, sigKL;
94 std::vector<double> xi;
95 std::vector<double> freqx, lam1Dx;
96
97 };
98
99 }
100}
101
102#endif
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 15, 23:04, 2025)