Re: Saving problem parameters in snapshots

27 views
Skip to first unread message

Keaton Burns

unread,
Jun 7, 2024, 2:47:12 PMJun 7
to dedalu...@googlegroups.com
Hi Matt,

I’d suggest making a field to wrap each parameter, and then outputting those directly. E.g.

A = dist.Field(name='a')
A['g'] = a
 
snapshots.add_task(A)

Best,
-Keaton


On Jun 7, 2024 at 9:53:21 AM, mncr...@gmail.com <mncr...@gmail.com> wrote:
Hi,

I'm attempting to save problem parameters by defining a constant field 'One' and then saving One*C in the snapshots. This works for C != 0, but for C = 0 it throws a dtype error. My question is; is there a way around this error? Or a better way of saving parameters in snapshots?

Thanks,

Matt


Error:

```
Traceback (most recent call last):
  File "/reserved/local/mcrowe/Dedalus3_Scripts/Georgi_Modons/modon_1_layer.py", line 194, in <module>
    snap.add_task(One*alpha, name='alpha')
  File "/local/mcrowe/miniconda3/envs/dedalus3/lib/python3.12/site-packages/dedalus/core/evaluator.py", line 453, in add_task
    super().add_task(*args, **kw)
  File "/local/mcrowe/miniconda3/envs/dedalus3/lib/python3.12/site-packages/dedalus/core/evaluator.py", line 310, in add_task
    task['dtype'] = op.dtype
                    ^^^^^^^^
AttributeError: 'int' object has no attribute 'dtype'
```

Code to replicate this:

```
import numpy as np
import dedalus.public as d3

a,b = 1, 0

coords = d3.CartesianCoordinates('x', 'y')
dist = d3.Distributor(coords, dtype=np.float64)
psi = dist.Field(name='psi')
One = dist.Field(name='One')
One['g'] = 1.0

problem = d3.IVP([psi], namespace=locals())
problem.add_equation("dt(psi) = 1")
solver = problem.build_solver(d3.RK222)
solver.stop_sim_time = 10

snap = solver.evaluator.add_file_handler('test_snap', sim_dt=1, max_writes=100)
snap.add_task(One*a, name='a')
snap.add_task(One*b, name='b')

while solver.proceed:
  solver.step(0.01)
```

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/9e8d502b-4166-425b-944b-8d32fde57ebfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages