예제 #1
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]]))
예제 #2
0
    },
    {
        'node_list': cn,
        'comp': 2,
        'value': lambda x: 0.0
    },
]
# Symmetry plane
cn = fenode_select(fens, box=numpy.array([W, W, 0, L, 0, H]), inflate=htol)
essential.append({'node_list': cn, 'comp': 0, 'value': lambda x: 0.0})
model_data['boundary_conditions']['essential'] = essential

# Traction on the free end
bfes = mesh_boundary(fes)
fesel = fe_select(fens, bfes, box=[0, W, L, L, 0, H], inflate=htol)
fi = ForceIntensity(magn=lambda x, J: numpy.array([0, 0, magn]))
tsfes = bfes.subset(fesel)
sfemm = FEMMDeforLinear(fes=tsfes, integration_rule=TriRule(npts=3))
traction = [{'femm': sfemm, 'force_intensity': fi}]
model_data['boundary_conditions']['traction'] = traction

# Call the solver
algo_defor_linear.statics(model_data)
for action, time in model_data['timings']:
    print(action, time, ' sec')

geom = model_data['geom']
u = model_data['u']

tipn = fenode_select(fens, box=[0, W, L, L, 0, H])
uv = u.values[tipn, :]
예제 #3
0
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)
start = time.time()
# lu = splu(K)
# T = lu.solve(F)
# T = spsolve(K, F, use_umfpack=True)
T, info = minres(K, F)
print(info)
temp.scatter_sysvec(T)
예제 #4
0
k = 1.0  # thermal conductivity
m = MatHeatDiff(thermal_conductivity=numpy.array([[k, 0.0], [0.0, k]]))
start = time.time()
N = 50
Length, Width, nL, nW = 1.0, 1.0, N, N
fens, fes = t3_ablock(Length, Width, nL, nW)
fes.other_dimension = lambda conn, N, x: 1.0
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)),
    'heat_generation':
    ForceIntensity(magn=lambda x, J: -6.0)
}]
bfes = mesh_boundary(fes)
model_data['boundary_conditions'] = {
    'essential': [{
        'node_list': connected_nodes(bfes),
        'value': lambda x: 1.0 + x[0]**2 + 2 * x[1]**2
    }]
}

# Call the solver
steady_state(model_data)
for action, time in model_data['timings']:
    print(action, time, ' sec')

plot_temperature(model_data)