<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Turhan,<div class=""><br class=""></div><div class="">Sorry for noticing your message lateā€¦</div><div class=""><br class=""></div><div class="">I attach some lines here of defining a (velocity) divergence field. You can change "velocity_x,y,z" to any vector field you want.</div><div class=""><br class=""></div><div class="">##################################################</div><div class=""><br class=""></div><div class="">import yt</div><div class="">from yt.fields.derived_field import ValidateSpatial</div><div class=""><br class=""></div><div class=""><div class="">@yt.derived_field(name='div_velocity', units='1/code_time',</div><div class="">                           validators = [ValidateSpatial(1,</div><div class="">                           ['velocity_x','velocity_y','velocity_z'])])</div><div class="">def _div_velocity(field,data):</div><div class="">    sl_left = slice(None, -2, None)</div><div class="">    sl_right = slice(2, None, None)</div><div class="">    div_fac = 2.0</div><div class="">    ds = div_fac * data['dx'].flat[0]</div><div class="">    f  = data["velocity_x"][sl_right,1:-1,1:-1]/ds</div><div class="">    f -= data["velocity_x"][sl_left ,1:-1,1:-1]/ds</div><div class="">    if data.ds.dimensionality > 1:</div><div class="">        ds = div_fac * data['dy'].flat[0]</div><div class="">        f += data["velocity_y"][1:-1,sl_right,1:-1]/ds</div><div class="">        f -= data["velocity_y"][1:-1,sl_left ,1:-1]/ds</div><div class="">    if data.ds.dimensionality > 2:</div><div class="">        ds = div_fac * data['dz'].flat[0]</div><div class="">        f += data["velocity_z"][1:-1,1:-1,sl_right]/ds</div><div class="">        f -= data["velocity_z"][1:-1,1:-1,sl_left ]/ds</div><div class="">    new_field = np.zeros(data["velocity_x"].shape, dtype='float64')</div><div class="">    new_field = data.ds.arr(new_field,'1/code_time')</div><div class="">    new_field[1:-1,1:-1,1:-1] = f</div><div class="">    return new_field</div></div><div class=""><br class=""></div><div class=""><div class="">##################################################</div></div><div class=""><br class=""><div class="">
<div class=""><div class="">Best wishes,</div><div class="">--</div><div class="">Suoqing JI</div><div class="">Ph.D Candidate</div><div class="">Department of Physics</div><div class="">University of California, Santa Barbara</div><div class=""><a href="http://web.physics.ucsb.edu/~suoqing" class="">http://web.physics.ucsb.edu/~suoqing</a></div></div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Oct 27, 2016, at 2:24 PM, Britton Smith <<a href="mailto:brittonsmith@gmail.com" class="">brittonsmith@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Turhan,<div class=""><br class=""></div><div class="">If you have a copy of the yt source, I suggest having a look the file yt/fields/vector_operations.py.  In there, you will find a function called _divergence which illustrates how to create a divergence field.  Additionally, I recommend looking for where that function is put to use in that file for an example of how to add such a field to the list of known fields.</div><div class=""><br class=""></div><div class="">Britton</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Oct 18, 2016 at 2:32 PM, turhan nasri <span dir="ltr" class=""><<a href="mailto:turhannasri@gmail.com" target="_blank" class="">turhannasri@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class="">Hi people, <br class=""><br class=""></div>I wish to see the sliceplots of "divergence of velocity" fields in yt. I see yt has an example of how to derive gradient of a scalar field , is there any example to show how to derive  new field for divergence too ? <br class=""><br class=""></div>Best<span class="HOEnZb"><font color="#888888" class=""><br class=""></font></span></div><span class="HOEnZb"><font color="#888888" class="">Turhan<br class=""></font></span></div>
<br class="">______________________________<wbr class="">_________________<br class="">
yt-users mailing list<br class="">
<a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/<wbr class="">listinfo.cgi/yt-users-<wbr class="">spacepope.org</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">yt-users mailing list<br class=""><a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org<br class=""></div></blockquote></div><br class=""></div></body></html>