How to get the variable names of a PDESystem if using a symbolic array

I’m having a hard time understanding exactly how a PDESystem with independent array variables differs from a PDESystem initialized with other independent variables. For example, suppose I have the following two PDESystems

@parameters t z1 z2 z[1:2]
pde_system1 =  PDESystem(eq, bcs, domains, [t, z1, z2], [u(t, z1, z2)])
pde_system2 = PDESystem(eqs, bcs, domains, [t, z...], [u(t, z...)]) 

I can look at the independent variables and I would get

In: pde_system1.indvars
Out:  Num[t, z1, z2] 

In: pde_system2.indvars 
Out: Num[t, z[1], z[2]]

and both of these have type Vector{Num}. However, when I call ModelingToolkit.getname, I get

In: ModelingToolkit.getname(pde_system1.indvars) 
Out: [:t, :z1, :z2] 

In: ModelingToolkit.getname(pde_system2.indvars) 
Out: [:t, :z, :z] 

It seems to me that getname in the case of pde_system2 returns the name of the entire array instead of the name of the particular entry. I have two questions about this. First, why is this happening? Naively, it seems like because pde_system1.indvars and pde_system2.indvars have the same type, ModelingToolkit.getname should return names for each entry of the vector in both cases.

My second question is about how to address this. Is there a way to unpack the independent variables of pde_system2 so that ModelingToolkit.getname returns a vector of symbols where each symbol corresponds to the entry of the array variables?

@YingboMa @shashi

That’s the expected behavior so that you can do sys.z[1] while sys.z1 won’t make sense and might cause name collision.

Okay then, maybe it’s an X-Y problem. Why is this name required?

I’m working on extending NeuralPDE.jl so that it works with a PDESystem having independent variables that are a symbolic array.

Right now, I’m looking in symbolic_utilities.jl and I’m trying to modify this function to handle the case that the independent variables contain a symbolic array.

The issue is that the function Symbolics.nameof errors with symbolic arrays, but I was thinking I could circumvent this by unpacking z. Is there an easier way that I’m not seeing?

That makes sense to me.

As a related question, if vars has type Vector{Num}, then ModelingToolkit.getname(vars) throws an error, which is to be expected. However, ModelingToolkit.getname.(vars) does not. What does the .() operator do?

I looked in the documentation and on discourse but I couldn’t find any information.

1 Like

@ChrisRackauckas I need a little help thinking through how to do this. Could you please take a look at this issue on Github and let me know what you think?