Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inverse design Cp function #1311

Merged
merged 2 commits into from
Jun 29, 2021
Merged

Fix inverse design Cp function #1311

merged 2 commits into from
Jun 29, 2021

Conversation

pcarruscag
Copy link
Member

Proposed Changes

It had mpi problems and others: https://www.cfd-online.com/Forums/su2/236677-mpi-returns-wrong-objective-function-values.html

The target Cp file was also not formatted correctly, the residuals will change because of that.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with the '-Wall -Wextra -Wno-unused-parameter -Wno-empty-body' compiler flags, or simply --warnlevel=2 when using meson).
  • My contribution is commented and consistent with SU2 style.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp) , if necessary.

Copy link
Contributor

@WallyMaier WallyMaier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

}
}
}
if (!Surface_file.good()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not erroring in case the file is no bueno? "Unable to read from SurfaceCP file"

Currently it is some sort of silent error catch that gives "false" results but does not really communicate why. Or am I overlooking sth here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Because this function is always called and the result is always available as one of the outputs 🤷 and so it cannot throw an error.

@pcarruscag pcarruscag merged commit 1f92147 into develop Jun 29, 2021
@pcarruscag pcarruscag deleted the fix_cp_inv_design branch June 29, 2021 12:23
Copy link
Contributor

@TobiKattmann TobiKattmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I missed the last bus to this PR 🚏 🚌 ... so I am arriving just now 🐌 )

Thanks for getting into the details of this implementation and fixing this @pcarruscag 💐

* \param[in] geometry - Geometrical definition of the problem.
* \param[in] config - Definition of the particular problem.
*/
void Set_CpInverseDesign(CSolver *solver, CGeometry *geometry, CConfig *config);
void Set_CpInverseDesign(CSolver *solver, const CGeometry *geometry, const CConfig *config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for making the interface clearer with the consts

@@ -69,9 +69,9 @@ def main():
discadj_arina2k.cfg_dir = "disc_adj_euler/arina2k"
discadj_arina2k.cfg_file = "Arina2KRS.cfg"
discadj_arina2k.test_iter = 20
discadj_arina2k.test_vals = [2.189902, 1.635938, 47258.000000, 0.000000]
discadj_arina2k.test_vals = [-3.111181, -3.501516, 6.8705e-02, 0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the first to fields are residuals (i.e. quite an improvment by this bugfix), and good to see this fix is directly captured by the reg-test ... but this also tells 'dont trust the regression tests' :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

garbage in garbage out as with all things

}
}
}
if (!Surface_file.good()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not erroring in case the file is no bueno? "Unable to read from SurfaceCP file"

Currently it is some sort of silent error catch that gives "false" results but does not really communicate why. Or am I overlooking sth here

Comment on lines +752 to +753
if (!set)
cout << "WARNING: In file " << surfCp_filename << ", point " << iPointGlobal << " is not a vertex." << endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this warning (and some additional comments in this section)

Comment on lines +772 to +776
const auto Cp = solver->GetCPressure(iMarker, iVertex);
const auto CpTarget = solver->GetCPressureTarget(iMarker, iVertex);

PressDiff += Area * (CpTarget - Cp) * (CpTarget - Cp);
}
const auto Normal = geometry->vertex[iMarker][iVertex]->GetNormal();
const auto Area = GeometryToolbox::Norm(nDim, Normal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: We need to be careful on future PR's with these su2double auto's because like so as a single assignment it is correct but is looks straight forward e.g. to extend it to const auto Cp_rho = solver->GetCPressure(iMarker, iVertex) * rho (rho falling from the sky) which would then be incorrect because the auto for su2double active then evaluates to an expression.

Comment on lines +769 to +770
const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
if (!geometry->nodes->GetDomain(iPoint)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fai (For anyone's interest): this is the missing check of domain points that is mentioned in the cfd-online post

@jblueh jblueh mentioned this pull request Jul 6, 2021
5 tasks
@snow54 snow54 mentioned this pull request Jul 19, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants