Exemplo n.º 1
0
 def test__all_functions_defaults(self):
     axes = [
         cartesian.Axis1d(upper_limit=8, size=3),
         cartesian.Axis1d(upper_limit=10, size=5)
     ]
     mesh = Mesh(axes)
     for tested_method in [
             o for o in inspect.getmembers(objects2d)
             if inspect.isfunction(o[1])
     ]:
         tested_method[1](mesh)
Exemplo n.º 2
0
 def test__sanity(self):
     axes = [cartesian.Axis1d(name="X", units="cm", size=2, upper_limit=10),
             cartesian.Axis1d(name="Y", units="cm", size=2, upper_limit=10)]
     m = mesh.Mesh(axes)
     mod = model.Model(mesh=m)
     from tomomak.detectors import detector_array
     kw_list = [dict(mesh=m, p1=(-5, 0), p2=(15, 15), width=0.5, divergence=0.1),
                dict(mesh=m, p1=(-5, 5), p2=(15, 5), width=0.5, divergence=0.1)]
     det = detector_array.detector_array(func_name='tomomak.detectors.detectors2d.detector2d', kwargs_list=kw_list)
     mod.detector_signal = [0, 0]
     mod.detector_geometry = det
from tomomak.transform import rescale
from tomomak.transform import pipeline
from tomomak.detectors import detectors2d, signal
from tomomak.iterators import ml, algebraic
from tomomak.iterators import statistics
import tomomak.constraints.basic

# This is an example of a basic framework functionality.
# You will learn how to use framework, steps you need to follow in order to get the solution.
# More advanced features are described in advanced examples.

# The first step is to create coordinate system. We will consider 2D cartesian coordinates.
# Let's create coordinate mesh. First axis will consist of 20 segments. Second - of 30 segments.
# This means that solution will be described by the 20x30 array.
axes = [
    cartesian.Axis1d(name="X", units="cm", size=20, upper_limit=10),
    cartesian.Axis1d(name="Y", units="cm", size=30, upper_limit=10)
]
mesh = mesh.Mesh(axes)
# Now we can create Model.
# Model is one of the basic tomomak structures which stores information about geometry, solution and detectors.
# At present we only have information about the geometry.
mod = model.Model(mesh=mesh)
# Now let's create synthetic 2D object to study.
# We will consider triangle.
real_solution = objects2d.polygon(mesh, [(1, 1), (4, 8), (7, 2)])
# Model.solution is the solution we are looking for.
# It will be obtained at the end of this example.
# However, if you already know supposed solution (for example you get it with simulation),
# you can use it as first approximation by setting Model.solution = *supposed solution*.
# Recently we've generated test object, which is, of course, real solution.
Exemplo n.º 4
0
# We will start with multiprocessing. Most of the functions and methods are parallelized automatically,
# however some of them need special treatment since they use external libraries.
# This fact is stated in the function docstring.
# To turn parallelization on run script with environmental variable TM_MP set to number of desired cores.
# Or just write in your script:
#        import os
#        os.environ["TM_MP"] = "8"
# If you use Windows, due to Python limitations, you have to guard your script with
# If __name__ == "__main__":

# We will start with If __name__ == "__main__" block
if __name__ == "__main__":

    # Let's create model
    axes = [cartesian.Axis1d(name="X", units="cm", size=40, upper_limit=10),
            cartesian.Axis1d(name="Y", units="cm", size=40, upper_limit=10)]
    mesh = mesh.Mesh(axes)
    mod = model.Model(mesh=mesh)

    # Now let's calculate detector geometry
    start = time.time()
    det = detectors2d.fan_detector_array(mesh=mesh,
                                         focus_point=(5, 5),
                                         radius=11,
                                         fan_num=10,
                                         line_num=40,
                                         width=1,
                                         divergence=0.2)
    end = time.time()
    print("Serial calculation took {} s.".format(end - start))
Exemplo n.º 5
0
from tomomak.mesh import mesh
from tomomak.mesh import cartesian, polar, toroidal
from tomomak.detectors import detectors2d, detectors3d
import numpy as np

# One of the main TOMOMAK features is the ability to work with non-Cartesian coordinates.
# Non-cartesian coordinates may be used only for spatial axes.
# Non-spatial axes may be irregular, however they should be orthogonal to other axes,
# so cartesian.Axis1d class should be used.
# This tutorial explains how to work with non-Cartesian coordinates correctly.

# Let's start with 2D polar coordinate system. This system has two coordinates: rotation angle and radius.
# In Tomomak radius can be represented using 1D cartesian axis and rotation - using 1D polar axis.
# When TOMOMAK sees this axes combination, it automatically understands that we work with 2D polar system.
axes = [polar.Axis1d(name="phi", units="rad", size=15),
        cartesian.Axis1d(name="R", units="cm", size=20, upper_limit=10)]
m = mesh.Mesh(axes)
mod = model.Model(mesh=m)

# Now let's see what the circle will look like in this coordinate system
mod.solution = objects2d.ellipse(m, ax_len=(5.2, 5.2))
mod.plot2d()
# Well, looks fine, but how it will look in cartesian coordinates?
# You don't need to use your imagination - just use cartesian_coordinates=True argument:
mod.plot2d(cartesian_coordinates=True)
# We see that there is a small artefact ring around the circle due to the fact,
# that this cells does not fully intersect with out object, but everything else looks fine.
# Now let's look at the rectangle
mod.solution = objects2d.rectangle(m,  size=(5, 5))
mod.plot2d(cartesian_coordinates=True)
# Well, it doesn't look like a rectangle at all. So important lesson is to choose correct mesh,
Exemplo n.º 6
0
from tomomak.solver import *
from tomomak.test_objects import objects2d
from tomomak.mesh import mesh
from tomomak.mesh import cartesian, polar, toroidal
from tomomak.transform import rescale
from tomomak.transform import pipeline
from tomomak.detectors import detectors2d, signal
from tomomak.iterators import ml, algebraic
from tomomak.iterators import statistics
import tomomak.constraints.basic
import numpy as np
from mayavi import mlab
import numpy as np
import inspect

axes = [cartesian.Axis1d(upper_limit=8, size=3), cartesian.Axis1d(upper_limit=10, size=5)]
m = Mesh(axes)
c = objects2d.cone(m)
axes = [toroidal.Axis1d(radius=20, name="theta", units="rad", size=15, upper_limit=np.pi),
        polar.Axis1d(name="phi", units="rad", size=12),
        cartesian.Axis1d(name="R", units="cm", size=11, upper_limit=10)]
m = mesh.Mesh(axes)
mod = model.Model(mesh=m)
res = objects2d.ellipse(m, ax_len=(5.2, 5.2), index=(1, 2), broadcast=False)
real_solution = geometry3d.broadcast_2d_to_3d(res, m, (1, 2), 0, 'solution')
mod.solution = real_solution
det = detectors2d.detector2d(m, (-50, -50), (50, 50), 40, index=(1, 2), radius_dependence=False, broadcast=False)
det_geom = geometry3d.broadcast_2d_to_3d(det, m, (1,2), 0, 'detector_geometry')
mod.detector_geometry = [det_geom]
mod.plot3d(cartesian_coordinates=True, data_type='detector_geometry_n', limits=(0, 2))
mod.plot3d(cartesian_coordinates=True)