<div dir="ltr"><div><div>Hi Nathan,<br><br></div>Thanks a lot! I have modified that file and is working perfectly. No problem about being doubtful.<br><br></div>Cheers!<br></div><div class="gmail_extra"><br><div class="gmail_quote">2016-05-19 0:20 GMT-03:00 Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi José,<div><br></div><div>You're right, of course. This incorrect behavior is due to a bug in yt. Thank you for the report! Sorry for being doubtful initially, it took me a while to convince myself that yt's answers were wrong.</div><div><br></div><div>This is a particularly pernicious error, since it will only show up for fields that need field parameters and ghost zones, which unfortunately is apparently not well tested...</div><div><br></div><div>I've made a pull request to fix this here:</div><div><br></div><div><a href="https://bitbucket.org/yt_analysis/yt/pull-requests/2186" target="_blank">https://bitbucket.org/yt_analysis/yt/pull-requests/2186</a><br></div><div><br></div><div>With this fix, I now get this plot for the gradient of your Omega field:</div><div><br></div><div><a href="http://i.imgur.com/DEo4mBw.png" target="_blank">http://i.imgur.com/DEo4mBw.png</a><br></div><div><br></div><div>Let me know if you need help merging in my fix locally. Hopefully it will be merged into the development branch of yt within the next few days.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Nathan</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 18, 2016 at 9:28 PM, José Utreras <span dir="ltr"><<a href="mailto:jutreras@das.uchile.cl" target="_blank">jutreras@das.uchile.cl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thanks Nathan! Now I don't see that division in the field.<br></div>Still, I think that it does not have the correct values. In this case, with the correct definition of the field, the derivative should be positive for x>0 and negative for x<0.<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-05-18 20:43 GMT-03:00 Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jose,<div class="gmail_extra"><br><div class="gmail_quote"><span>On Wed, May 18, 2016 at 1:17 PM, José Utreras <span dir="ltr"><<a href="mailto:jutreras@das.uchile.cl" target="_blank">jutreras@das.uchile.cl</a>></span> wrote:<br></span><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Hi everyone,<br> I'm having the following problem: I want to 
calculate the gradient field of the angular velocity which I have 
defined as follows:<br><br>>def _Omega(field,data):<br>>        if data.has_field_parameter("bulk_velocity"):<br>>                bv = data.get_field_parameter("bulk_velocity").in_units("cm/s")<br>>        else:<br>>                bv = data.ds.arr(np.zeros(3), "cm/s")<br>>        xv = data["gas","velocity_x"] - bv[0]<br>>        yv = data["gas","velocity_y"] - bv[1]<br>>        center = data.get_field_parameter('center')<br>>        x_hat = data["x"] - center[0]<br>>        y_hat = data["y"] - center[1]<br>>        r = np.sqrt(x_hat*x_hat+y_hat*y_hat)<br>>        x_hat /= r**2<br>>        y_hat /= r**2<br>><br>>        return np.sqrt((xv*y_hat-yv*x_hat)**2)<br></div></div></div></blockquote><div><br></div></span><div>The issue is this line ^</div><div><br></div><div>You're taking the absolute value of z component of the angular velocity, which introduces a discontinuity in the first derivative - that's the artifact you're seeing in your plots.  I think you really want to have:</div><div><br></div><div>> return (xv*y_hat-yv*x_hat)<br></div><div><br></div><div>Here's what Omega and the gradient look like with that definition:</div><div><br></div><div><a href="http://i.imgur.com/7ElXqw6.png" target="_blank">http://i.imgur.com/7ElXqw6.png</a><br></div><div><a href="http://i.imgur.com/fjoLXX3.png" target="_blank">http://i.imgur.com/fjoLXX3.png</a><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span><div dir="ltr"><div><div>>yt.add_field("Omega", function=_Omega,take_log=False,      units=r"1/yr",validators=[ValidateParameter('bulk_velocity')])<br><br></div>This is the profile I have got using the SlicePlot tool:<br><br><a href="https://drive.google.com/file/d/0B43CkTTj8OeOcy16TkFaZlBhRE0/view?usp=sharing" target="_blank">https://drive.google.com/file/d/0B43CkTTj8OeOcy16TkFaZlBhRE0/view?usp=sharing</a><br><br>So, it is a function of radius. The density is also a function of radius. The problem is that if I use<br><br>>grad_fields = ds.add_gradient_fields(("gas","Omega"))<br>>slice = yt.SlicePlot(ds, 'z', "Omega_gradient_x")<br><br></div>I get this<br><div><br><a href="https://drive.google.com/file/d/0B43CkTTj8OeOLUxGVUJSQ253TE0/view?usp=sharing" target="_blank">https://drive.google.com/file/d/0B43CkTTj8OeOLUxGVUJSQ253TE0/view?usp=sharing</a><br><br>​the sign should only change across x=0. I did the same for the density field getting the correct behaviour. <br>I've also tried to define the gradient field <br><br>>def _vorticity_2(field, data):<br>>    f  = (data[ftype, "Omega"][sl_right,sl_center,sl_center] -<br>>          data[ftype, "Omega"][sl_left,sl_center,sl_center]) \<br>>          / (div_fac*just_one(data["index", "dx"]))<br>><br>>    new_field = data.ds.arr(np.zeros_like(data[ftype, "velocity_z"],<br>>                                          dtype=np.float64),<br>>                            f.units)<br>>    new_field[sl_center, sl_center, sl_center] = f<br>>    return new_field<br><br>But I got the same results. <br><br>If I'm doing something wrong please let me know.<br><br>Cheers!<br><br>Jose Utreras <br></div></div>
<br></span><span>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></span></blockquote></div><br></div></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>