Skip to content

Conversation

@economon
Copy link
Member

Proposed Changes

Give a brief overview of your contribution here in a few sentences.

This PR adds the necessary base classes (solver, numerics, variable) for having an arbitrary number of scalar transport equations added to flow problems in a segregated manner (alongside a turbulence model, if necessary). Most of the numerics is shared with the scalar methods for the turb. solvers to eliminate duplication, and it should be easy now to add child classes for any new scalar transport models.

In this PR, only a passive scalar has been implemented, but we are also building on this framework to add a flamelet model for combustion as a child class. A passive scalar test case will be added.

It still needs more work, but it is important to have the skeleton merged now to lessen the burden of fixing conflicts with the ongoing restructuring in driver, variable, output, etc.

Related Work

Resolve any issues (bug fix or feature request), note any related PRs, or mention interactions with the work of others, if any.

N/A

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • 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).
  • My contribution is commented and consistent with SU2 style.
  • I have added a test case that demonstrates my contribution, if necessary.

Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

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

I like the feature and the implementation is clean. I do not like the architecture, something like this should be the base of the turbulence and heat solvers.


#include "../../Common/include/mpi_structure.hpp"
#include <CLI11.hpp>
#include "../../externals/CLI11/CLI11.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

Is this what we do for other externals or is adding to the include path more appropriate?

* \brief Set all the primitive variables for incompressible flows
*/
bool SetPrimVar(su2double eddy_visc, su2double turb_ke, CFluidModel *FluidModel);
bool SetPrimVar(su2double eddy_visc, su2double turb_ke, su2double *scalar, CFluidModel *FluidModel);
Copy link
Member

Choose a reason for hiding this comment

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

Not applicable to Euler?


bool turbulent = ((config->GetKind_Solver() == RANS) ||
(config->GetKind_Solver() == DISC_ADJ_RANS));
bool turb_SST = ((turbulent) && (config->GetKind_Turb_Model() == SST));
Copy link
Member

Choose a reason for hiding this comment

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

Are you missing SST_SUS now?

CSolver **solver_container,
CNumerics *numerics,
CNumerics *second_numerics,
CConfig *config,
Copy link
Member

Choose a reason for hiding this comment

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

Indentation

/*--- Mass diffusivity coefficients. ---*/

second_numerics->SetDiffusionCoeff(node[iPoint]->GetDiffusivity(),
NULL);
Copy link
Member

Choose a reason for hiding this comment

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

More indentation

*/

void Upwind_Residual(CGeometry *geometry,
CSolver **solver_container,
Copy link
Member

Choose a reason for hiding this comment

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

Are we supposed to shorten the names? Otherwise we start having inconsistencies between driver, solver, etc.

if (scalar)
switch (config->GetKind_Scalar_Model()) {
case PASSIVE_SCALAR: case PROGRESS_VARIABLE:
nVar_Scalar = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Hardcoded nVar? How does one add more scalar variables?


/*--- Mean flow primitive variables using gradient reconstruction and limiters ---*/

Gradient_i = solver_container[FLOW_SOL]->node[iPoint]->GetGradient_Primitive();
Copy link
Member

Choose a reason for hiding this comment

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

This is what the turbulent solver does almost verbatim. Are you moving the heat and turbulence solvers to this framework?

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be possible without too much effort... actually this is already done for the convective schemes. The two next targets are the viscous scheme in numerics (one more base class) and then both the turb and heat solvers can inherit from the base scalar solver class in order to remove some duplication (like viscous residual above) - needs to be done with some care

Copy link
Contributor

@clarkpede clarkpede Aug 28, 2019

Choose a reason for hiding this comment

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

This is great work. I'm glad to see you've made my base classes from the turbulence solver even more general. Edit: I just noticed you said you're doing it for the viscous numerics as well. Looks great!

Copy link
Member

Choose a reason for hiding this comment

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

Great, it would be nice to re-use the muscl reconstruction bit of the code done in UpwindResidual too.

Copy link
Member

Choose a reason for hiding this comment

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

I want to change my mind, can you keep the solvers as is for now? (merging #753 is triple the work otherwise...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I avoid just the solvers? Does it cause an issue to adjust the viscous numerics?

I would like to clean up some things for this PR and hook up the new output classes for the scalars too if that won't cause any problems for you either.

Copy link
Member

Choose a reason for hiding this comment

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

Numerics is ok to change, selfish request but if the turbulence and heat solvers are changed significantly, I would have to re-apply the changes to them, unless you do that work already in the framework of #753 :p

Copy link
Member Author

Choose a reason for hiding this comment

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

I have now updated the classes so that all of the turbulent convective, viscous, and variable classes inherit from a scalar base class versions. This removes some duplicate code. I have not yet adjusted the solver classes, since this is a little more delicate.

Btw, this PR has now also been updated with the new contiguous variable structures and the new output.

bool turb_SST = ((turbulent) && (config->GetKind_Turb_Model() == SST));
bool turb_SA = ((turbulent) && (config->GetKind_Turb_Model() == SA));

/*--- Dimension of the problem --> passive scalar will only ever
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason for only 1 variable?

lowerlimit = new su2double[nVar];
upperlimit = new su2double[nVar];

lowerlimit[0] = -1.0e15;
Copy link
Member

Choose a reason for hiding this comment

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

not from config?

@economon economon changed the title General Scalar Transport Framework WIP General Scalar Transport Framework Aug 28, 2019
Copy link
Contributor

@oleburghardt oleburghardt left a comment

Choose a reason for hiding this comment

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

Hi Tom, this looks good to me, just a couple of questions below.

I'm sure you've already talked about including the new output structure in this PR. Is this the plan then?

Another concern of mine is how to proceed with all the weakly_coupled_heat-related lines. As you know, by adding the heat equation to the incompressible solver they became obsolete and I thought one should just leave them there in order to replace them by a general scalar model one day. Now we have them side by side.
Though nothing's wrong with keeping them anyway, I'm just interested in your view on that (see related comment on flow solver positions).

*/
inline void SetDiffusivity(su2double val_diffusivity,
unsigned short val_ivar) {
Diffusivity[val_ivar] = val_diffusivity;
Copy link
Contributor

@oleburghardt oleburghardt Sep 25, 2019

Choose a reason for hiding this comment

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

It comes handy that the scalar transport framework is based on (mass) diffusivity. That way it works very similar to the heat solver which is also based on (thermal) diffusivity and one could easily make it a child class.


}

void CAvgGradScalar_General::ExtraADPreaccIn() { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the preaccumulation really be wrapped? I don't find them too disturbing on the ComputeResidual-level. (I'd even prefer to have them there because errors might be more apparent then for the reader.)
It's also not entirely consistent so far, e.g. here or for grid velocity.

Copy link
Contributor

@clarkpede clarkpede Sep 25, 2019

Choose a reason for hiding this comment

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

I can chime in here. In the original implementation, the "scalars" were the turbulent variables. I was the one who applied the template design pattern to the AvgGrad classes in PR #422.

The motivation was this: In the template method, you find what's the same and what's different between similar functions. You put everything that's the same into a base class (e.g. CAvgGradScalar), then put everything that differs into functions implemented by the derived class. So some SetPreaccIn calls are common, and they're in the base class (CAvgGradScalar). Those that are unique are included in the ExtraADPreaccIn. That way the CAvgGradScalar::ComputeResidual just does this for all child classes:

void CAvgGradScalar::ComputeResidual(su2double *val_residual,
                                     su2double **Jacobian_i,
                                     su2double **Jacobian_j,
                                     CConfig *config) {

  AD::StartPreacc();
  AD::SetPreaccIn(Coord_i, nDim); AD::SetPreaccIn(Coord_j, nDim);
  AD::SetPreaccIn(Normal, nDim);
  AD::SetPreaccIn(ScalarVar_Grad_i, nVar, nDim);
  AD::SetPreaccIn(ScalarVar_Grad_j, nVar, nDim);
  AD::SetPreaccIn(Diffusion_Coeff_i, nVar);
  AD::SetPreaccIn(Diffusion_Coeff_j, nVar);
  if (correct_gradient) {
    AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(ScalarVar_j, nVar);
  }
  ExtraADPreaccIn();

Now, if you're OK with code duplication, then all the SetPreaccIn calls could be made in derived classes. But it's impossible to put them all in the ComputeResidual class because not all derived classes use the same variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see (I've overseen the _General extension to spot the overload), thanks for the explanation! I didn't notice the new templated structure..
Problems due to erroneous preaccumulation happened quite often to me (and they are very hard to track down), so that's why I'm so worried about those lines :D - though it's not reason enough for duplicating the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you missed it, then I would recommend that @economon add some explanatory comments about CAvgGradScalar_General either in the header file or the cpp file. That way future code readers/programmers don't have the same confusion.

Unless @economon would prefer that I do the comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for highlighting this topic. I think @oleburghardt's experience is very common. I had the same issue: the adjoint was not working with scalars for a while before I realized I had made the same mistake of not adding the diffusivity to the preaccumulation. This is very easy to overlook.

Is there a change we can make that fits within the newer class structure of @clarkpede to make this more clear? Comments are great, but they become stale over time, and folks may not read it. It would be good to force folks to consider this somehow while writing the routines. Is there a clever way to error check this for instance?

const int HEAT_SOL = 5; /*!< \brief Position of the heat equation in the solution solver array. */
const int ADJHEAT_SOL = 6; /*!< \brief Position of the adjoint heat equation in the solution solver array. */

const int SCALAR_SOL = 5; /*!< \brief Position of the scalar transport solution in the solver container array. */
Copy link
Contributor

@oleburghardt oleburghardt Sep 25, 2019

Choose a reason for hiding this comment

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

That excludes cases where we might want to run heat and scalar solvers side by side. So is the idea then to have a scalar solver with a (additional) temperature variable or should the weak coupling option be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that, in the end, it would be great to make the current heat solver a solver for heat conduction in solids alone by removing the weakly coupled option. This will simplify things throughout the code a bit and let us remove some things. After/with this PR, it should be easier to have the heat solver inherit from some of the base scalar classes, as I have done for the turbulence models.

@economon economon mentioned this pull request Oct 15, 2019
3 tasks
@pcarruscag pcarruscag mentioned this pull request Oct 31, 2019
4 tasks
@economon economon changed the title WIP General Scalar Transport Framework WIP General Framework for Scalar Transport Equations Nov 12, 2019
@stale
Copy link

stale bot commented Jan 14, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still a relevant issue please comment on it to restart the discussion. Thank you for your contributions.

@stale stale bot added the stale label Jan 14, 2020
@economon
Copy link
Member Author

WIP

@stale stale bot removed the stale label Jan 15, 2020
@stale
Copy link

stale bot commented Mar 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still a relevant issue please comment on it to restart the discussion. Thank you for your contributions.

@stale stale bot added the stale label Mar 15, 2020
@economon
Copy link
Member Author

WIP.. some folks in the community are using this as a base for their development

@stale stale bot removed the stale label Mar 17, 2020
@stale
Copy link

stale bot commented May 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still a relevant issue please comment on it to restart the discussion. Thank you for your contributions.

@stale stale bot added the stale label May 16, 2020
@economon
Copy link
Member Author

Same status as above

@stale stale bot removed the stale label May 16, 2020
@stale
Copy link

stale bot commented Jul 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still a relevant issue please comment on it to restart the discussion. Thank you for your contributions.

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.

7 participants