Peano
Loading...
Searching...
No Matches
DiffusionPDE.py
Go to the documentation of this file.
1stencil = """// calculate laplacian of velocities
2 tarch::la::Vector<DIMENSIONS, double> velocityLaplacian(0.0);
3 for (int velocity = 0; velocity < DIMENSIONS; ++velocity) {
4 velocityLaplacian(velocity) += (
5 (QRight0[Shortcuts::u + velocity] - QRight0[Shortcuts::backgroundU + velocity])
6 - 2 * (Q[Shortcuts::u + velocity] - Q[Shortcuts::backgroundU + velocity])
7 + (QLeft0[Shortcuts::u + velocity] - QLeft0[Shortcuts::backgroundU + velocity])
8 ) / (h(0) * h(0));
9 }
10
11 for (int velocity = 0; velocity < DIMENSIONS; ++velocity) {
12 velocityLaplacian(velocity) += (
13 (QTop0[Shortcuts::u + velocity] - QTop0[Shortcuts::backgroundU + velocity])
14 - 2 * (Q[Shortcuts::u + velocity] - Q[Shortcuts::backgroundU + velocity])
15 + (QDown0[Shortcuts::u + velocity] - QDown0[Shortcuts::backgroundU + velocity])
16 ) / (h(1) * h(1));
17 }
18
19 #if DIMENSIONS == 3
20 for (int velocity = 0; velocity < DIMENSIONS; ++velocity) {
21 velocityLaplacian(velocity) += (
22 (QFront0[Shortcuts::u + velocity] - QFront0[Shortcuts::backgroundU + velocity])
23 - 2 * (Q[Shortcuts::u + velocity] - Q[Shortcuts::backgroundU + velocity])
24 + (QBack0[Shortcuts::u + velocity] - QBack0[Shortcuts::backgroundU + velocity])
25 ) / (h(2) * h(2));
26 }
27 #endif
28
29 for (int velocity = 0; velocity < DIMENSIONS; ++velocity) {
30 if (std::fabs(velocityLaplacian(velocity)) < VELOCITY_THRESHOLD) {
31 velocityLaplacian(velocity) = 0.0;
32 }
33 }
34
35 QNew[Shortcuts::u] = Q[Shortcuts::u] + dt * Q[Shortcuts::nu] * velocityLaplacian(Shortcuts::u);
36 QNew[Shortcuts::v] = Q[Shortcuts::v] + dt * Q[Shortcuts::nu] * velocityLaplacian(Shortcuts::v);
37 #if DIMENSIONS == 3
38 QNew[Shortcuts::w] = Q[Shortcuts::w] + dt * Q[Shortcuts::nu] * velocityLaplacian(Shortcuts::w);
39 #endif
40
41 // calculate temperature derivative
42 auto temperaturePerturbation = [](const double* Q) {
43 //calculate temperature based on energy density
44 const auto uSquared = Q[Shortcuts::u] * Q[Shortcuts::u];
45 const auto vSquared = Q[Shortcuts::v] * Q[Shortcuts::v];
46 #if DIMENSIONS == 3
47 const auto wSquared = Q[Shortcuts::w] * Q[Shortcuts::w];
48 const auto squaredVelocities = uSquared + vSquared + wSquared;
49 #else
50 const auto squaredVelocities = uSquared + vSquared;
51 #endif
52 const auto internalEnergy = Q[Shortcuts::E] - 0.5 * (Q[Shortcuts::rho] * squaredVelocities);
53 const auto M = Q[Shortcuts::O2] + Q[Shortcuts::O] + Q[Shortcuts::N2];
54 const auto iM = 1.0 / M;
55 const auto gamma = (1.4 * (M - Q[Shortcuts::O]) + 1.67 * Q[Shortcuts::O]) * iM;
56 const auto meanMolecularMass = (MOLAR_MASS_NITROGEN * Q[Shortcuts::N2] + MOLAR_MASS_MOLECULAR_OXYGEN * Q[Shortcuts::O2] + MOLAR_MASS_ATOMIC_OXYGEN * Q[Shortcuts::O]) * iM; // in kg/mol
57 const auto temperature = (internalEnergy * (gamma - 1.0) * meanMolecularMass) / ( Q[Shortcuts::rho] * UNIVERSAL_GAS_CONSTANT);
58
59 // take derivative only of temperature perturbation
60 return temperature - Q[Shortcuts::backgroundT];
61 };
62
63 double temperatureLaplacian = 0.0;
64 const auto doubleTemperaturePerturbationQ = 2 * temperaturePerturbation(Q);
65
66 // x direction
67 temperatureLaplacian += (
68 temperaturePerturbation(QRight0)
69 - doubleTemperaturePerturbationQ
70 + temperaturePerturbation(QLeft0)
71 ) / (h(0) * h(0));
72
73 // y direction
74 temperatureLaplacian += (
75 temperaturePerturbation(QTop0)
76 - doubleTemperaturePerturbationQ
77 + temperaturePerturbation(QDown0)
78 ) / (h(1) * h(1));
79
80 #if DIMENSIONS == 3
81 // z direction
82 temperatureLaplacian += (
83 temperaturePerturbation(QFront0)
84 - doubleTemperaturePerturbationQ
85 + temperaturePerturbation(QBack0)
86 ) / (h(2) * h(2));
87 #endif
88
89 if (std::fabs(temperatureLaplacian) < TEMPERATURE_THRESHOLD) {
90 temperatureLaplacian = 0.0;
91 }
92
93 QNew[Shortcuts::T] = Q[Shortcuts::T] + dt * Q[Shortcuts::kappa] * temperatureLaplacian;
94
95 // compute new pressure based on updated temperature
96 const auto M = Q[Shortcuts::O2] + Q[Shortcuts::O] + Q[Shortcuts::N2];
97 const auto iM = 1.0 / M;
98 const auto gamma = (1.4 * (M - Q[Shortcuts::O]) + 1.67 * Q[Shortcuts::O]) * iM;
99 const auto meanMolecularMass = (MOLAR_MASS_NITROGEN * Q[Shortcuts::N2] + MOLAR_MASS_MOLECULAR_OXYGEN * Q[Shortcuts::O2] + MOLAR_MASS_ATOMIC_OXYGEN * Q[Shortcuts::O]) * iM; // in kg/mol
100
101 const auto pressureNew = Q[Shortcuts::rho] * UNIVERSAL_GAS_CONSTANT * QNew[Shortcuts::T] / meanMolecularMass;
102
103 // compute new energy based on new pressure
104 #if DIMENSIONS == 3
105 const auto vSqNew = QNew[Shortcuts::u] * QNew[Shortcuts::u] + QNew[Shortcuts::v] * QNew[Shortcuts::v] + QNew[Shortcuts::w] * QNew[Shortcuts::w];
106 #else
107 const auto vSqNew = QNew[Shortcuts::u] * QNew[Shortcuts::u] + QNew[Shortcuts::v] * QNew[Shortcuts::v];
108 #endif
109
110 QNew[Shortcuts::E] = pressureNew / (gamma - 1.0) + 0.5 * Q[Shortcuts::rho] * vSqNew;
111
112 return;"""