idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.76k stars 1.05k forks source link

Add an alias for std::vector<VariableName> #26639

Closed lingzou closed 9 months ago

lingzou commented 9 months ago

Reason

The ultimate goal is for convenience.

In MOOSE kernels or objects similar, when a coupled variable is needed, the InputParameters::addCoupledVar API is used, which is really InputParameters::addParam<std::vector<VariableName>> under the hood.

When in the code (not in a MOOSE input file) this coupled variable is supplied, we do something like this: pars.set<std::vector<VariableName>>("coupled_var") = {"my_var"}

To keep things consistent and convenient, it seems reasonable to define an alias, such as: typedef std::vector<VariableName> CoupledVar

Design

See discussion above.

Add typedef std::vector<VariableName> CoupledVar in MooseTypes.h, such that InputParameters::addCoupledVar and pars.set<CoupledVar>("coupled_var") = {"my_var"} are consistent.

Impact

Will not change existing APIs, nor user inputs.

lingzou commented 9 months ago

@GiudGiud and @lindsayad what would be the best naming for the alias? CoupledVar, CoupledVariables, VariableNameVector, or something else? I prefer the first one because of its consistency.

GiudGiud commented 9 months ago

VariableNameVector would be fine for me

My only concern with CoupledVariables is that it points to the Coupleable interface, but what if it s used outside that context? Maybe we can also not use it when we are not dealing with a coupleable context

lingzou commented 9 months ago

VariableNameVector would be fine for me

My only concern with CoupledVariables is that it points to the Coupleable interface, but what if it s used outside that context? Maybe we can also not use it when we are not dealing with a coupleable context

Makes great sense to me. We can use VariableNameVector.

lindsayad commented 9 months ago

I personally prefer CoupledName as this is already used for a typedef in the contact, tensor mechanics, and navier-stokes modules

lindsayad commented 9 months ago

addCoupledVar can be used in any MooseObject's validParams whether it inherits from the Coupleable interface or not. Similarly I think users can be comfortable using CoupledName in non-"Coupleable" contexts

lingzou commented 9 months ago

A quick search finds multiple typedef of CoupledName

contact/include/actions/ContactAction.h:  typedef std::vector<VariableName> CoupledName;
navier_stokes/include/actions/CNSAction.h:  typedef std::vector<VariableName> CoupledName;
navier_stokes/include/actions/INSAction.h:  typedef std::vector<VariableName> CoupledName;
navier_stokes/include/base/NSFVBase.h:  typedef std::vector<VariableName> CoupledName;
tensor_mechanics/include/actions/DomainIntegralAction.h:  typedef std::vector<VariableName> CoupledName;

How about we keep CoupledName and move the typedef into MooseTypes.h and make it a moose thing?

lindsayad commented 9 months ago

I think that's a good idea!