コード例 #1
0
    def test_first_example(self):
        import math
        import numpy
        from numpy import array
        from spyfe.materials.mat_heatdiff import MatHeatDiff
        from spyfe.fesets.surfacelike import FESetT3
        from spyfe.femms.femm_heatdiff import FEMMHeatDiff
        from spyfe.fields.nodal_field import NodalField
        from spyfe.integ_rules import TriRule
        from spyfe.fenode_set import FENodeSet
        # These are the constants in the problem, k is kappa
        a = 2.5  # radius on the columnthe
        dy = a / 2 * math.sin(15. / 180 * math.pi)
        dx = a / 2 * math.cos(15. / 180 * math.pi)
        Q = 4.5  # internal heat generation rate
        k = 1.8  # thermal conductivity
        m = MatHeatDiff(thermal_conductivity=array([[k, 0.0], [0.0, k]]))
        Dz = 1.0  # thickness of the slice
        xall = array([[0, 0], [dx, -dy], [dx, dy], [2 * dx, -2 * dy],
                      [2 * dx, 2 * dy]])
        fes = FESetT3(array([[1, 2, 3], [2, 4, 5], [2, 5, 3]]) - 1)

        femm = FEMMHeatDiff(material=m,
                            fes=fes,
                            integration_rule=TriRule(npts=1))
        fens = FENodeSet(xyz=xall)
        geom = NodalField(fens=fens)
        temp = NodalField(nfens=xall.shape[0], dim=1)
        temp.set_ebc([3, 4])
        temp.apply_ebc()
        temp.numberdofs(node_perm=[1, 2, 0, 4, 3])
        print(temp.dofnums)
        K = femm.conductivity(geom, temp)
        print(K)
コード例 #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]]))
コード例 #3
0
ファイル: Poisson_fe_H20.py プロジェクト: PetrKryslUCSD/SPyFE
fens, fes = h8_to_h20(fens, fes)
fes.gradbfunpar(numpy.array([0, 0, 0]))
geom = NodalField(fens=fens)

vtkexport("Poisson_fe_H20_mesh", fes, geom)
print('Mesh generation', time.time() - start)
bfes = mesh_boundary(fes)
cn = connected_nodes(bfes)

temp = NodalField(nfens=fens.count(), dim=1)
for j in cn:
    temp.set_ebc([j],
                 val=boundaryf(fens.xyz[j, 0], fens.xyz[j, 1], fens.xyz[j, 2]))
temp.apply_ebc()
femm = FEMMHeatDiff(material=m,
                    fes=fes,
                    integration_rule=GaussRule(dim=3, order=3))
S = femm.connection_matrix(geom)
perm = reverse_cuthill_mckee(S, symmetric_mode=True)
temp.numberdofs(node_perm=perm)
# temp.numberdofs()
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)
コード例 #4
0
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)
コード例 #5
0
right = fe_select(fens,
                  bfes,
                  facing=True,
                  direction=lambda x: numpy.array([1.0, 0.0]),
                  tolerance=0.99)
top = fe_select(fens,
                bfes,
                facing=True,
                direction=lambda x: numpy.array([0.0, +1.0]),
                tolerance=0.99)
topright = numpy.concatenate((top, right))
print('Mesh generation', time.time() - start)
model_data = {}
model_data['fens'] = fens
model_data['regions'] \
    = [{'femm': FEMMHeatDiff(material=m, fes=fes,
                             integration_rule=TriRule(npts=1))}
       ]
model_data['boundary_conditions'] \
    = {'essential': [{'node_list': connected_nodes(bfes.subset(bottom)),
                      'temperature': lambda x: 100.0
                      }],
       'surface_transfer': [{'femm': FEMMHeatDiffSurface(fes=bfes.subset(topright),
                                                         integration_rule=GaussRule(dim=1, order=1),
                                                         surface_transfer_coeff=lambda x: 750.0),
                             'ambient_temperature': lambda x: 0.0
                             }]
       }

# Call the solver
steady_state(model_data)
print(model_data['timings'])