Skip to content

Commit 8c976d5

Browse files
committed
exact jacobians for negative model
1 parent 823c335 commit 8c976d5

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar<FlowIndices> {
163163
if (nu_tilde_ij >= 0.0) {
164164
fn_ij = 1.0;
165165
} else {
166-
fn_ij = (cn1 + Xi_ij*Xi_ij*Xi_ij)/(cn1 - Xi_ij*Xi_ij*Xi_ij);
166+
fn_ij = (cn1 + pow(Xi_ij,3.0))/(cn1 - pow(Xi_ij, 3.0));
167167
}
168168

169169
/*--- Second Term (LHS) ---*/
@@ -172,7 +172,7 @@ class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar<FlowIndices> {
172172
if (zeta_i >= 0.0) {
173173
fn_i = 1.0;
174174
} else {
175-
fn_i = (cn1 + zeta_i*zeta_i*zeta_i)/(cn1 - zeta_i*zeta_i*zeta_i);
175+
fn_i = (cn1 + pow(zeta_i,3.0))/(cn1 - pow(zeta_i,3.0));
176176
}
177177

178178
/* Following Diskin's implementation from 10.2514/1.J064629, they propose a new fn function
@@ -184,11 +184,51 @@ class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar<FlowIndices> {
184184
su2double term_2 = cb2*nu_tilde_i*fn_i* Proj_Mean_GradScalarVar[0]/sigma;
185185
Flux[0] = term_1 - term_2;
186186

187-
/*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/
187+
/*--- Buffer to store the values (prints values of all nodes per iteration) DELTE LATER
188+
unsigned long iter = config->GetMultizone_Problem() ? config->GetOuterIter() : config->GetInnerIter();
189+
std::ofstream URF_log_file
190+
191+
URF_log_file.open("diffusion_term.dat", std::ios::app);
192+
if (!URF_log_file.is_open()) {
193+
std::cerr << "Unable to open under_relaxation_buffer.dat" << std::endl;
194+
}
195+
196+
if (URF_log_file.is_open())
197+
URF_log_file << "Iteration: " << iter << std::endl;
198+
URF_log_file << "Term 1: " << term_1/Proj_Mean_GradScalarVar[0] << std::endl;
199+
URF_log_file << "Term 2: " << term_2/Proj_Mean_GradScalarVar[0] << std::endl;
200+
URF_log_file << "Total: " << (term_1 - term_2)/Proj_Mean_GradScalarVar[0] << std::endl;
201+
URF_log_file << std::endl;
202+
}
203+
204+
if (URF_log_file.is_open()) {
205+
URF_log_file.close();
206+
} ---*/
207+
208+
/*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients
209+
* To form the exact jacobians, use the chain and product rules.
210+
* The diffusion coefficient following Diskin's approach is: A = (nu_ij + (1+cb2)*nut_tilde_ij -cb2*nu_tilde_i)*fn_i = B*fni
211+
* dA/dnut_i = dB/dnut_i *fni + dfni/dnut_i * B
212+
* dA/dnut_j = dB/dnut_j *fni + dfni/dnut_j * B
213+
* Flux = A*Proj_Mean_GradScalarVar[0]
214+
* dFlux_dnuti = dA/dnut_i*Proj_Mean_GradScalarVar[0] + A*proj_vector_ij
215+
* dFlux_dnutj = dA/dnut_j*Proj_Mean_GradScalarVar[0] - A*proj_vector_ij
216+
* ---*/
217+
218+
su2double B = (nu_ij + (1 + cb2)*nu_tilde_ij) - cb2*nu_tilde_i;
219+
220+
su2double dfni_dnut_i = -1 * 6.0*(cb2-1)*cn1*pow(nu_i+nu_j,3.0) * pow(((cb2-1)*nu_tilde_i-(cb2+1)*nu_tilde_j),2.0) / pow((pow(((cb2+1)*nu_tilde_i - (cb2+1)*nu_tilde_j),3.0) + cn1*pow((nu_i+nu_j),3.0)),2.0);
221+
su2double dfni_dnut_j = 6.0*(cb2-1)*cn1*pow(nu_i+nu_j,3.0) * pow(((cb2+1)*nu_tilde_j-(cb2-1)*nu_tilde_i),2.0) / pow((pow(((cb2+1)*nu_tilde_j - (cb2-1)*nu_tilde_i),3.0) - cn1*pow((nu_i+nu_j),3.0)),2.0);
222+
223+
su2double dB_dnut_i = 0.5*(1 - cb2);
224+
su2double dB_dnut_j = 0.5*(1 + cb2);
225+
226+
su2double dA_dnut_i = (dB_dnut_i *fn_i + dfni_dnut_i * B)/sigma;
227+
su2double dA_dnut_j = (dB_dnut_j *fn_i + dfni_dnut_j * B)/sigma;
188228

189229
if (implicit) {
190-
Jacobian_i[0][0] = (0.5*Proj_Mean_GradScalarVar[0]-nu_ij*proj_vector_ij)/sigma;
191-
Jacobian_j[0][0] = (0.5*Proj_Mean_GradScalarVar[0]+nu_ij*proj_vector_ij)/sigma;
230+
Jacobian_i[0][0] = dA_dnut_i*Proj_Mean_GradScalarVar[0] + B*fn_i*proj_vector_ij/sigma;
231+
Jacobian_j[0][0] = dA_dnut_j*Proj_Mean_GradScalarVar[0] - B*fn_i*proj_vector_ij/sigma;
192232
}
193233
}
194234

0 commit comments

Comments
 (0)