<jupyter_start><jupyter_text>Tutorial: Setting the finite difference field value In this tutorial, we demonstrate different ways of setting the FD field values.Firstly, we import the required Field class.<jupyter_code>from finitedifferencefield import Field<jupyter_output><empty_output><jupyter_text>We create a three-dimansional vector field with domain that spans between:- minimum coordinate $c_\text{min} = (1, 1, 1)$ and- maximum coordinate $c_\text{max} = (10, 6, 9)$,with discretisation $d = (1, 1, 1)$.<jupyter_code>cmin = (1, 1, 1)
cmax = (10, 6, 9)
d = (1, 1, 1)
dim = 3<jupyter_output><empty_output><jupyter_text>After all the parameters are specified, we can create a field and give it a name.<jupyter_code>field = Field(cmin, cmax, d, dim=dim, name='fdfield')<jupyter_output><empty_output><jupyter_text>As it was shown in the previous tutorial, if we do not specify the field value, it is initialised as zero-field.<jupyter_code>(field.f == 0).all()<jupyter_output><empty_output><jupyter_text>Setting using float/intWe can set the field value using a single float/int value. In this case all components of the vector field will be the same at all FD field discretisation points.<jupyter_code>value = 3

field.set(value)<jupyter_output><empty_output><jupyter_text>This can be checked using:<jupyter_code>(field.f == 3).all()
field.average()<jupyter_output><empty_output><jupyter_text>Setting using list/tupleIf the FD field value is specified using a tuple, list, or numpy array, all compoenents of the vector field must be specified separately.<jupyter_code>value = (1, -2, 3.5)
field.set(value)
(field.f[:, :, :, 0] == 1).all() and \
(field.f[:, :, :, 1] == -2).all() and \
(field.f[:, :, :, 2] == 3.5).all()
field.average()<jupyter_output><empty_output><jupyter_text>Setting using Python functionSo far, we set the FD field value to be constant - space invariant. Now, using a Python function, we set the field value using a Python function.Python function should have a single argument which is a tuple of coordinates (x, y, z) and returns the tuple of an appropriate dimension for the field whose value we set.If we want to set the field value so that:$$f(x, y, z) = (2x, 2y+x, x+z)$$<jupyter_code>def value(pos):
    x, y, z = pos
    
    fx = 2*x
    fy = 2*y + x
    fz = x+z
    
    return (fx, fy, fz)

field.set(value)<jupyter_output><empty_output><jupyter_text>Knowing the field values, we expect that the field value at point (1.5, 2.5, 3.5) should be:$$f(1.5, 2.5, 3.5) = (3, 6.5, 5)$$If we sample the field at that point we get:<jupyter_code>c = (1.5, 2.5, 3.5)
field(c)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12433460076045627, 'fraction_numerical': 0.023193916349809884, 'mean_word_length': 5.104408352668213, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '561883', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 953, 'n_tokens_neox': 904, 'n_words': 315, 'path': 'docs/ipynb/setting_fd_field.ipynb', 'repo_name': 'joommf/finitedifferencefield', 'size': '2630'}