Exemple #1
0
 def test_boundary(self):
     import numpy
     from spyfe.meshing.generators.triangles import t3_ablock
     from spyfe.meshing.modification import mesh_boundary
     Length, Width, nL, nW = 3.1, 2.2, 3, 2
     fens, fes = t3_ablock(Length, Width, nL, nW)
     #   print(fes.conn)
     bfes = mesh_boundary(fes)
Exemple #2
0
    def test_Poisson_t3(self):
        from context import spyfe
        from spyfe.meshing.generators.triangles import t3_ablock
        from spyfe.meshing.modification import mesh_boundary
        from spyfe.meshing.selection import connected_nodes
        from numpy import array
        from spyfe.materials.mat_heatdiff import MatHeatDiff
        from spyfe.femms.femm_heatdiff import FEMMHeatDiff
        from spyfe.fields.nodal_field import NodalField
        from spyfe.integ_rules import TriRule
        from spyfe.force_intensity import ForceIntensity
        from scipy.sparse.linalg import spsolve
        import time
        from spyfe.meshing.exporters.vtkexporter import vtkexport

        start0 = time.time()

        # These are the constants in the problem, k is kappa
        boundaryf = lambda x, y: 1.0 + x**2 + 2 * y**2
        Q = -6  # internal heat generation rate
        k = 1.0  # thermal conductivity
        m = MatHeatDiff(thermal_conductivity=array([[k, 0.0], [0.0, k]]))
        Dz = 1.0  # thickness of the slice
        start = time.time()
        N = 5
        Length, Width, nL, nW = 1.0, 1.0, N, N
        fens, fes = t3_ablock(Length, Width, nL, nW)
        print('Mesh generation', time.time() - start)
        bfes = mesh_boundary(fes)
        cn = connected_nodes(bfes)
        geom = NodalField(fens=fens)
        temp = NodalField(nfens=fens.count(), dim=1)
        for index in cn:
            temp.set_ebc([index],
                         val=boundaryf(fens.xyz[index, 0], fens.xyz[index, 1]))
        temp.apply_ebc()
        temp.numberdofs()
        femm = FEMMHeatDiff(material=m,
                            fes=fes,
                            integration_rule=TriRule(npts=1))
        start = time.time()
        fi = ForceIntensity(magn=lambda x, J: Q)
        F = femm.distrib_loads(geom, temp, fi, 3)
        print('Heat generation load', time.time() - start)
        start = time.time()
        F += femm.nz_ebc_loads_conductivity(geom, temp)
        print('NZ EBC load', time.time() - start)
        start = time.time()
        K = femm.conductivity(geom, temp)
        print('Matrix assembly', time.time() - start)
        start = time.time()
        temp.scatter_sysvec(spsolve(K, F))
        print('Solution', time.time() - start)
        print(temp.values)
        print('Done', time.time() - start0)
        from numpy.testing import assert_array_almost_equal
        assert_array_almost_equal(temp.values[-4:-1],
                                  array([[3.16], [3.36], [3.64]]))
Exemple #3
0
 def test_fenode_map(self):
     from spyfe.fenode_to_fe_map import fenode_to_fe_map
     from spyfe.meshing.generators.triangles import t3_ablock
     N = 2
     Length, Width, nL, nW = 1.0, 1.0, N, N
     fens, fes = t3_ablock(Length, Width, nL, nW)
     print(fes.conn)
     femap = fenode_to_fe_map(fens.count(), fes.conn)
     print(femap)
Exemple #4
0
 def test_one_based_initial(self):
     import numpy
     from spyfe.meshing.generators.triangles import t3_ablock
     Length, Width, nL, nW = 3.1, 2.2, 3, 2
     fens, fes = t3_ablock(Length, Width, nL, nW)
     print(fes.conn)
     assert fes.conn[0, 2] == 5
     assert fes.conn[2, 0] == 4
     #fes.conn[0, 0]
     print(fens.xyz[0, :])
Exemple #5
0
 def test_connection_matrix(self):
     from context import spyfe
     from spyfe.meshing.generators.triangles import t3_ablock
     from spyfe.femms.femm_base import FEMMBase
     from spyfe.fields.nodal_field import NodalField
     from spyfe.integ_rules import TriRule
     N = 5
     Length, Width, nL, nW = 1.0, 1.0, N, N
     fens, fes = t3_ablock(Length, Width, nL, nW)
     geom = NodalField(fens=fens)
     femm = FEMMBase(fes=fes, integration_rule=TriRule(npts=1))
     S = femm.connection_matrix(geom)
Exemple #6
0
 def test_subset(self):
     from context import spyfe
     from spyfe.meshing.generators.triangles import t3_ablock
     from spyfe.femms.femm_base import FEMMBase
     from spyfe.fields.nodal_field import NodalField
     from spyfe.integ_rules import TriRule
     N = 2
     Length, Width, nL, nW = 1.0, 1.0, N, N
     fens, fes = t3_ablock(Length, Width, nL, nW)
     print(fes.conn)
     # print(fes.label)
     fes.subset([0, 3, 5])
     print(fes.conn)
Exemple #7
0
from scipy.sparse.linalg import spsolve
import time
from spyfe.meshing.exporters.vtkexporter import vtkexport

start0 = time.time()

# These are the constants in the problem, k is kappa
boundaryf = lambda x, y: 1.0 + x**2 + 2 * y**2
Q = -6  # internal heat generation rate
k = 1.0  # thermal conductivity
m = MatHeatDiff(thermal_conductivity=array([[k, 0.0], [0.0, k]]))
Dz = 1.0  # thickness of the slice
start = time.time()
N = 5
Length, Width, nL, nW = 1.0, 1.0, N, N
fens, fes = t3_ablock(Length, Width, nL, nW)
print('Mesh generation', time.time() - start)
bfes = mesh_boundary(fes)
cn = connected_nodes(bfes)
geom = NodalField(fens=fens)
temp = NodalField(nfens=fens.count(), dim=1)
for index in cn:
    temp.set_ebc([index],
                 val=boundaryf(fens.xyz[index, 0], fens.xyz[index, 1]))
temp.apply_ebc()
temp.numberdofs()
femm = FEMMHeatDiff(material=m, fes=fes, integration_rule=TriRule(npts=1))
start = time.time()
fi = ForceIntensity(magn=lambda x, J: Q)
F = femm.distrib_loads(geom, temp, fi, 3)
print('Heat generation load', time.time() - start)
Exemple #8
0
from spyfe.femms.femm_heatdiff import FEMMHeatDiff
from spyfe.femms.femm_heatdiff_surface import FEMMHeatDiffSurface
from spyfe.integ_rules import TriRule, GaussRule
from spyfe.force_intensity import ForceIntensity
import time
from spyfe.algorithms.algo_heatdiff import steady_state
from spyfe.algorithms.algo_heatdiff import plot_temperature

start0 = time.time()

k = 52.0  # thermal conductivity
m = MatHeatDiff(thermal_conductivity=numpy.array([[k, 0.0], [0.0, k]]))
start = time.time()
Width, nW = 0.6, 20
Heightb, nHb = 0.2, 20
fens1, fes1 = t3_ablock(Width, Heightb, nW, nHb)
Heightt, nHt = 0.8, 20
fens2, fes2 = t3_ablock(Width, Heightt, nW, nHt)
fens2.xyz[:, 1] += Heightb
tolerance = Heightb / nHb / 100
fens, fes1, fes2 = merge_meshes(fens1, fes1, fens2, fes2, tolerance)
fes = fes1.cat(fes2)
fes.other_dimension = lambda conn, N, x: 1.0
bfes = mesh_boundary(fes)
bottom = fe_select(fens,
                   bfes,
                   facing=True,
                   direction=lambda x: numpy.array([0.0, -1.0]),
                   tolerance=0.99)

right = fe_select(fens,
Exemple #9
0
 def test_T3_ablock(self):
     from spyfe.meshing.generators.triangles import t3_ablock
     Length, Width, nL, nW = 2.0, 1.0, 4, 3
     fens, fes = t3_ablock(Length, Width, nL, nW)
     print(fes.conn)