I want to define my own field. For example, pressure.
```python
fields = {
'temperature' : ('real', 1, 'Omega', 1),
'pressure' : ('real', 1, 'Omega', 1),
}
variables = {
't' : ('unknown field', 'temperature', 0),
's' : ('test field', 'temperature', 't'),
'p' : ( 'parameter field', 'pressure', {'setter' : 'get_pressure'} ),
}
def get_pressure(ts, coors, region=None):
z = coors[:,2]
return z
functions = {
'get_pressure': (get_pressure,),
}
```
The idea is to create very primitive field that depends on z coordinates.
Now I want to export the grad(p) to the output mesh. And so I add this in
postprocess function:
```python
p_grad = pb.evaluate('ev_grad.i.Omega(p)', mode='el_avg', verbose=False)
out['p'] = Struct(name='output_data', mode='cell', data=p_grad, dofs=None)
```
But I get the following error:
ValueError: argument p not found!
What I'm doing wrong?
And how can I export the pressure field itself (not its gradient)?
The answer from Robert Cimrman:
Hi,
In a post-processing function, the only variables that are defined are
those
that are used in the equations. If p is not used, you need to create it, as
shown below (also how to save p and its cell averages.
def post_process(out, pb, state, extend=False):
from sfepy.base.base import Struct
pvar = pb.create_variables(['p'])['p']
pvar.time_update(None, pb.functions)
out.update(pvar.create_output())
ap = pb.evaluate('ev_volume_integrate.i.Omega(p)', mode='el_avg',
p=pvar,
verbose=False)
out['ap'] = Struct(name='output_data', mode='cell', data=ap, dofs=None)
p_grad = pb.evaluate('ev_grad.i.Omega(p)', mode='el_avg', p=pvar,
verbose=False)
out['gp'] = Struct(name='output_data', mode='cell', data=p_grad,
dofs=None)
return out
r.
PS: This might be interesting to others, so, if you do not mind, you can
forward it to the list.