Datasets:

Modalities:
Text
Formats:
parquet
Libraries:
Datasets
pandas
prompt
stringlengths
174
59.5k
completion
stringlengths
7
228
api
stringlengths
12
64
import numpy as nm from sfepy.linalg import dot_sequences from sfepy.terms.terms import Term, terms class DivGradTerm(Term): r""" Diffusion term. :Definition: .. math:: \int_{\Omega} \nu\ \nabla \ul{v} : \nabla \ul{u} \mbox{ , } \int_{\Omega} \nu\ \nabla \ul{u} : \nabla \ul{w} \\ \int_{\Omega} \nabla \ul{v} : \nabla \ul{u} \mbox{ , } \int_{\Omega} \nabla \ul{u} : \nabla \ul{w} :Arguments 1: - material : :math:`\nu` (viscosity, optional) - virtual : :math:`\ul{v}` - state : :math:`\ul{u}` :Arguments 2: - material : :math:`\nu` (viscosity, optional) - parameter_1 : :math:`\ul{u}` - parameter_2 : :math:`\ul{w}` """ name = 'dw_div_grad' arg_types = (('opt_material', 'virtual', 'state'), ('opt_material', 'parameter_1', 'parameter_2')) arg_shapes = {'opt_material' : '1, 1', 'virtual' : ('D', 'state'), 'state' : 'D', 'parameter_1' : 'D', 'parameter_2' : 'D'} modes = ('weak', 'eval') function = staticmethod(terms.term_ns_asm_div_grad) def d_div_grad(self, out, grad1, grad2, mat, vg, fmode): sh = grad1.shape g1 = grad1.reshape((sh[0], sh[1], sh[2] * sh[3])) g2 = grad2.reshape((sh[0], sh[1], sh[2] * sh[3])) aux = mat *
dot_sequences(g1[..., None], g2, 'ATB')
sfepy.linalg.dot_sequences
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh =
Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp')
sfepy.discrete.fem.Mesh.from_file
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain =
FEDomain('domain', mesh)
sfepy.discrete.fem.FEDomain
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 =
Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1)
sfepy.discrete.fem.Field.from_args
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 =
Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1)
sfepy.discrete.fem.Field.from_args
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 =
EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0})
sfepy.discrete.conditions.EssentialBC
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity =
Material(name='viscosity', value=1.25e-3)
sfepy.discrete.Material
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 =
FieldVariable('u', 'unknown', field_1)
sfepy.discrete.FieldVariable
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 =
FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u')
sfepy.discrete.FieldVariable
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 =
FieldVariable(name='p', kind='unknown', field=field_2)
sfepy.discrete.FieldVariable
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 =
FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p')
sfepy.discrete.FieldVariable
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 =
Integral('i1', order=2)
sfepy.discrete.Integral
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 =
Integral('i2', order=3)
sfepy.discrete.Integral
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 =
Equation('balance', t1+t2-t3)
sfepy.discrete.Equation
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 =
Equation('incompressibility', t4)
sfepy.discrete.Equation
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs =
Equations([eq1,eq2])
sfepy.discrete.Equations
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls =
ScipyDirect({})
sfepy.solvers.ls.ScipyDirect
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls = ScipyDirect({}) nls_status =
IndexedStruct()
sfepy.base.base.IndexedStruct
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls = ScipyDirect({}) nls_status = IndexedStruct() nls =
Newton({'i_max' : 20, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6}, lin_solver=ls, status=nls_status)
sfepy.solvers.nls.Newton
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls = ScipyDirect({}) nls_status = IndexedStruct() nls = Newton({'i_max' : 20, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6}, lin_solver=ls, status=nls_status) pb =
Problem('Navier-Stokes', equations=eqs)
sfepy.discrete.Problem
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls = ScipyDirect({}) nls_status = IndexedStruct() nls = Newton({'i_max' : 20, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6}, lin_solver=ls, status=nls_status) pb = Problem('Navier-Stokes', equations=eqs) pb.set_bcs(ebcs=Conditions([ebc_1, ebc_2, ebc_3])) pb.set_solver(nls) status =
IndexedStruct()
sfepy.base.base.IndexedStruct
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls = ScipyDirect({}) nls_status = IndexedStruct() nls = Newton({'i_max' : 20, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6}, lin_solver=ls, status=nls_status) pb = Problem('Navier-Stokes', equations=eqs) pb.set_bcs(ebcs=Conditions([ebc_1, ebc_2, ebc_3])) pb.set_solver(nls) status = IndexedStruct() state = pb.solve(status=status, save_results=True) out = state.create_output_dict() pb.save_state('Navier_Stokes.vtk', out=out) view =
Viewer('Navier_Stokes.vtk')
sfepy.postprocess.viewer.Viewer
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 28 09:33:53 2020 @author: dhulls """ from __future__ import print_function from __future__ import absolute_import from argparse import ArgumentParser import numpy as nm import sys sys.path.append('.') from sfepy.base.base import IndexedStruct, Struct from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem) from sfepy.discrete.fem import Mesh, FEDomain, Field from sfepy.terms import Term from sfepy.discrete.conditions import Conditions, EssentialBC, InitialCondition from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton from sfepy.postprocess.viewer import Viewer from sfepy.postprocess.probes_vtk import ProbeFromFile, Probe import numpy as np helps = { 'show' : 'show the results figure', } from sfepy import data_dir parser = ArgumentParser() parser.add_argument('--version', action='version', version='%(prog)s') parser.add_argument('-s', '--show', action="store_true", dest='show', default=False, help=helps['show']) options = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/3d/fluid_mesh.inp') domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field_1 = Field.from_args(name='3_velocity', dtype=nm.float64, shape=3, region=omega, approx_order=1) field_2 = Field.from_args(name='pressure', dtype=nm.float64, shape=1, region=omega, approx_order=1) region_0 = domain.create_region(name='Walls1', select='vertices in (y < -0.049)', kind='facet') region_1 = domain.create_region(name='Walls2', select='vertices in (y > 0.049)', kind='facet') region_2 = domain.create_region(name='Inlet', select='vertices in (x < -0.499)', kind='facet') region_3 = domain.create_region(name='Outlet', select='vertices in (x > -0.499)', kind='facet') ebc_1 = EssentialBC(name='Walls1', region=region_0, dofs={'u.[0,1,2]' : 0.0}) ebc_2 = EssentialBC(name='Walls2', region=region_1, dofs={'u.[0,1,2]' : 0.0}) ebc_3 = EssentialBC(name='Inlet', region=region_2, dofs={'u.0' : 1.0, 'u.[1,2]' : 0.0}) ebc_4 = EssentialBC(name='Outlet', region=region_3, dofs={'p':0.0, 'u.[1,2]' : 0.0}) viscosity = Material(name='viscosity', value=1.25e-3) variable_1 = FieldVariable('u', 'unknown', field_1) variable_2 = FieldVariable(name='v', kind='test', field=field_1, primary_var_name='u') variable_3 = FieldVariable(name='p', kind='unknown', field=field_2) variable_4 = FieldVariable(name='q', kind='test', field=field_2, primary_var_name='p') integral_1 = Integral('i1', order=2) integral_2 = Integral('i2', order=3) t1 = Term.new(name='dw_div_grad(viscosity.value, v, u)', integral=integral_2, region=omega, viscosity=viscosity, v=variable_2, u=variable_1) t2 = Term.new(name='dw_convect(v, u)', integral=integral_2, region=omega, v=variable_2, u=variable_1) t3 = Term.new(name='dw_stokes(v, p)', integral=integral_1, region=omega, v=variable_2, p=variable_3) t4 = Term.new(name='dw_stokes(u, q)', integral=integral_1, region=omega, u=variable_1, q=variable_4) eq1 = Equation('balance', t1+t2-t3) eq2 = Equation('incompressibility', t4) eqs = Equations([eq1,eq2]) ls = ScipyDirect({}) nls_status = IndexedStruct() nls = Newton({'i_max' : 20, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6}, lin_solver=ls, status=nls_status) pb = Problem('Navier-Stokes', equations=eqs) pb.set_bcs(ebcs=
Conditions([ebc_1, ebc_2, ebc_3])
sfepy.discrete.conditions.Conditions
r""" Piezo-elasticity problem - linear elastic material with piezoelectric effects. Find :math:`\ul{u}`, :math:`\phi` such that: .. math:: - \omega^2 \int_{Y} \rho\ \ul{v} \cdot \ul{u} + \int_{Y} D_{ijkl}\ e_{ij}(\ul{v}) e_{kl}(\ul{u}) - \int_{Y_2} g_{kij}\ e_{ij}(\ul{v}) \nabla_k \phi = 0 \;, \quad \forall \ul{v} \;, \int_{Y_2} g_{kij}\ e_{ij}(\ul{u}) \nabla_k \psi + \int_{Y} K_{ij} \nabla_i \psi \nabla_j \phi = 0 \;, \quad \forall \psi \;, where .. math:: D_{ijkl} = \mu (\delta_{ik} \delta_{jl}+\delta_{il} \delta_{jk}) + \lambda \ \delta_{ij} \delta_{kl} \;. """ import os import numpy as nm from sfepy import data_dir from sfepy.discrete.fem import MeshIO filename_mesh = data_dir + '/meshes/2d/special/circle_in_square.mesh' ## filename_mesh = data_dir + '/meshes/2d/special/circle_in_square_small.mesh' ## filename_mesh = data_dir + '/meshes/3d/special/cube_sphere.mesh' ## filename_mesh = data_dir + '/meshes/2d/special/cube_cylinder.mesh' omega = 1 omega_squared = omega**2 conf_dir = os.path.dirname(__file__) io =
MeshIO.any_from_filename(filename_mesh, prefix_dir=conf_dir)
sfepy.discrete.fem.MeshIO.any_from_filename
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh = Mesh.from_file(filename_in) if options.force_2d: data = list(mesh._get_io_data()) data[0] = data[0][:, :2] mesh = Mesh.from_data(mesh.name, *data) if scale is not None: if len(scale) == 1: tr = nm.eye(mesh.dim, dtype=nm.float64) * scale elif len(scale) == mesh.dim: tr = nm.diag(scale) else: raise ValueError('bad scale! (%s)' % scale) mesh.transform_coors(tr) if center is not None: cc = 0.5 * mesh.get_bounding_box().sum(0) shift = center - cc tr = nm.c_[nm.eye(mesh.dim, dtype=nm.float64), shift[:, None]] mesh.transform_coors(tr) if options.refine > 0: domain = FEDomain(mesh.name, mesh) output('initial mesh: %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) for ii in range(options.refine): output('refine %d...' % ii) domain = domain.refine() output('... %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) mesh = domain.mesh if options.tri_tetra > 0: conns = None for k, new_desc in [('3_8', '3_4'), ('2_4', '2_3')]: if k in mesh.descs: conns = mesh.get_conn(k) break if conns is not None: nelo = conns.shape[0] output('initial mesh: %d elements' % nelo) new_conns = elems_q2t(conns) nn = new_conns.shape[0] // nelo new_cgroups = nm.repeat(mesh.cmesh.cell_groups, nn) output('new mesh: %d elements' % new_conns.shape[0]) mesh = Mesh.from_data(mesh.name, mesh.coors, mesh.cmesh.vertex_groups, [new_conns], [new_cgroups], [new_desc]) if options.merge: desc = mesh.descs[0] coor, ngroups, conns = fix_double_nodes(mesh.coors, mesh.cmesh.vertex_groups, mesh.get_conn(desc), 1e-9) mesh = Mesh.from_data(mesh.name + '_merged', coor, ngroups, [conns], [mesh.cmesh.cell_groups], [desc]) if options.save_per_mat: desc = mesh.descs[0] conns, cgroups = mesh.get_conn(desc), mesh.cmesh.cell_groups coors, ngroups = mesh.coors, mesh.cmesh.vertex_groups mat_ids = nm.unique(cgroups) for mat_id in mat_ids: idxs = nm.where(cgroups == mat_id)[0] imesh = Mesh.from_data(mesh.name + '_matid_%d' % mat_id, coors, ngroups, [conns[idxs]], [cgroups[idxs]], [desc]) fbase, fext = op.splitext(filename_out) ifilename_out = '%s_matid_%d%s' % (fbase, mat_id, fext) io = MeshIO.for_format(ifilename_out, format=options.format, writable=True) output('writing %s...' % ifilename_out) imesh.write(ifilename_out, io=io) output('...done') io = MeshIO.for_format(filename_out, format=options.format, writable=True) cell_types = ', '.join(supported_cell_types[io.format])
output('writing [%s] %s...' % (cell_types, filename_out))
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh = Mesh.from_file(filename_in) if options.force_2d: data = list(mesh._get_io_data()) data[0] = data[0][:, :2] mesh = Mesh.from_data(mesh.name, *data) if scale is not None: if len(scale) == 1: tr = nm.eye(mesh.dim, dtype=nm.float64) * scale elif len(scale) == mesh.dim: tr = nm.diag(scale) else: raise ValueError('bad scale! (%s)' % scale) mesh.transform_coors(tr) if center is not None: cc = 0.5 * mesh.get_bounding_box().sum(0) shift = center - cc tr = nm.c_[nm.eye(mesh.dim, dtype=nm.float64), shift[:, None]] mesh.transform_coors(tr) if options.refine > 0: domain = FEDomain(mesh.name, mesh) output('initial mesh: %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) for ii in range(options.refine): output('refine %d...' % ii) domain = domain.refine() output('... %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) mesh = domain.mesh if options.tri_tetra > 0: conns = None for k, new_desc in [('3_8', '3_4'), ('2_4', '2_3')]: if k in mesh.descs: conns = mesh.get_conn(k) break if conns is not None: nelo = conns.shape[0] output('initial mesh: %d elements' % nelo) new_conns = elems_q2t(conns) nn = new_conns.shape[0] // nelo new_cgroups = nm.repeat(mesh.cmesh.cell_groups, nn) output('new mesh: %d elements' % new_conns.shape[0]) mesh = Mesh.from_data(mesh.name, mesh.coors, mesh.cmesh.vertex_groups, [new_conns], [new_cgroups], [new_desc]) if options.merge: desc = mesh.descs[0] coor, ngroups, conns = fix_double_nodes(mesh.coors, mesh.cmesh.vertex_groups, mesh.get_conn(desc), 1e-9) mesh = Mesh.from_data(mesh.name + '_merged', coor, ngroups, [conns], [mesh.cmesh.cell_groups], [desc]) if options.save_per_mat: desc = mesh.descs[0] conns, cgroups = mesh.get_conn(desc), mesh.cmesh.cell_groups coors, ngroups = mesh.coors, mesh.cmesh.vertex_groups mat_ids = nm.unique(cgroups) for mat_id in mat_ids: idxs = nm.where(cgroups == mat_id)[0] imesh = Mesh.from_data(mesh.name + '_matid_%d' % mat_id, coors, ngroups, [conns[idxs]], [cgroups[idxs]], [desc]) fbase, fext = op.splitext(filename_out) ifilename_out = '%s_matid_%d%s' % (fbase, mat_id, fext) io = MeshIO.for_format(ifilename_out, format=options.format, writable=True) output('writing %s...' % ifilename_out) imesh.write(ifilename_out, io=io) output('...done') io = MeshIO.for_format(filename_out, format=options.format, writable=True) cell_types = ', '.join(supported_cell_types[io.format]) output('writing [%s] %s...' % (cell_types, filename_out)) mesh.write(filename_out, io=io)
output('...done')
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list:
output('Supported readable mesh formats:')
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:')
output('--------------------------------')
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------')
output_mesh_formats('r')
sfepy.discrete.fem.meshio.output_mesh_formats
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r')
output('')
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('')
output('Supported writable mesh formats:')
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:')
output('--------------------------------')
sfepy.base.base.output
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------')
output_mesh_formats('w')
sfepy.discrete.fem.meshio.output_mesh_formats
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh =
Mesh.from_file(root + '.1.vtk')
sfepy.discrete.fem.Mesh.from_file
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk')
remove_files(dirname)
sfepy.base.ioutils.remove_files
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh =
Mesh.from_file(filename_in)
sfepy.discrete.fem.Mesh.from_file
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh = Mesh.from_file(filename_in) if options.force_2d: data = list(mesh._get_io_data()) data[0] = data[0][:, :2] mesh =
Mesh.from_data(mesh.name, *data)
sfepy.discrete.fem.Mesh.from_data
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh = Mesh.from_file(filename_in) if options.force_2d: data = list(mesh._get_io_data()) data[0] = data[0][:, :2] mesh = Mesh.from_data(mesh.name, *data) if scale is not None: if len(scale) == 1: tr = nm.eye(mesh.dim, dtype=nm.float64) * scale elif len(scale) == mesh.dim: tr = nm.diag(scale) else: raise ValueError('bad scale! (%s)' % scale) mesh.transform_coors(tr) if center is not None: cc = 0.5 * mesh.get_bounding_box().sum(0) shift = center - cc tr = nm.c_[nm.eye(mesh.dim, dtype=nm.float64), shift[:, None]] mesh.transform_coors(tr) if options.refine > 0: domain =
FEDomain(mesh.name, mesh)
sfepy.discrete.fem.FEDomain
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh = Mesh.from_file(filename_in) if options.force_2d: data = list(mesh._get_io_data()) data[0] = data[0][:, :2] mesh = Mesh.from_data(mesh.name, *data) if scale is not None: if len(scale) == 1: tr = nm.eye(mesh.dim, dtype=nm.float64) * scale elif len(scale) == mesh.dim: tr = nm.diag(scale) else: raise ValueError('bad scale! (%s)' % scale) mesh.transform_coors(tr) if center is not None: cc = 0.5 * mesh.get_bounding_box().sum(0) shift = center - cc tr = nm.c_[nm.eye(mesh.dim, dtype=nm.float64), shift[:, None]] mesh.transform_coors(tr) if options.refine > 0: domain = FEDomain(mesh.name, mesh) output('initial mesh: %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) for ii in range(options.refine): output('refine %d...' % ii) domain = domain.refine() output('... %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) mesh = domain.mesh if options.tri_tetra > 0: conns = None for k, new_desc in [('3_8', '3_4'), ('2_4', '2_3')]: if k in mesh.descs: conns = mesh.get_conn(k) break if conns is not None: nelo = conns.shape[0] output('initial mesh: %d elements' % nelo) new_conns = elems_q2t(conns) nn = new_conns.shape[0] // nelo new_cgroups = nm.repeat(mesh.cmesh.cell_groups, nn) output('new mesh: %d elements' % new_conns.shape[0]) mesh = Mesh.from_data(mesh.name, mesh.coors, mesh.cmesh.vertex_groups, [new_conns], [new_cgroups], [new_desc]) if options.merge: desc = mesh.descs[0] coor, ngroups, conns = fix_double_nodes(mesh.coors, mesh.cmesh.vertex_groups, mesh.get_conn(desc), 1e-9) mesh = Mesh.from_data(mesh.name + '_merged', coor, ngroups, [conns], [mesh.cmesh.cell_groups], [desc]) if options.save_per_mat: desc = mesh.descs[0] conns, cgroups = mesh.get_conn(desc), mesh.cmesh.cell_groups coors, ngroups = mesh.coors, mesh.cmesh.vertex_groups mat_ids =
nm.unique(cgroups)
sfepy.base.base.nm.unique
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option =
nm.array(option, dtype=nm.float64, ndmin=1)
sfepy.base.base.nm.array
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh =
Mesh.from_file(filename_in)
sfepy.discrete.fem.Mesh.from_file
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain =
FEDomain(mesh.name, mesh)
sfepy.discrete.fem.FEDomain
#!/usr/bin/env python """ Convert a mesh file from one SfePy-supported format to another. Examples:: $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s2.5 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.vtk -s0.5,2,1 -c 0 $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new.mesh --remesh='q2/0 a1e-8 O9/7 V' $ ./script/convert_mesh.py meshes/3d/cylinder.mesh new2.mesh --remesh='rq2/0 a1e-8 O9/7 V' """ from __future__ import absolute_import import sys import os.path as op from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter from sfepy.base.base import nm, output from sfepy.base.ioutils import remove_files from sfepy.discrete.fem import Mesh, FEDomain from sfepy.discrete.fem.meshio import (output_mesh_formats, MeshIO, supported_cell_types) from sfepy.discrete.fem.mesh import fix_double_nodes from sfepy.mesh.mesh_tools import elems_q2t helps = { 'scale' : 'scale factor (float or comma-separated list for each axis)' ' [default: %(default)s]', 'center' : 'center of the output mesh (0 for origin or' ' comma-separated list for each axis) applied after scaling' ' [default: %(default)s]', 'refine' : 'uniform refinement level [default: %(default)s]', 'format' : 'output mesh format (overrides filename_out extension)', 'list' : 'list supported readable/writable output mesh formats', 'merge' : 'remove duplicate vertices', 'tri-tetra' : 'convert elements: quad->tri, hexa->tetra', '2d' : 'force a 2D mesh by removing the z coordinates - assumes a 3D mesh' ' in the xy plane', 'save-per-mat': 'extract cells by material id and save them into' ' separate mesh files with a name based on filename_out and the id' ' numbers (preserves original mesh vertices)', 'remesh' : """when given, remesh the given mesh using tetgen. The options can be the following, separated by spaces, in this order: 1. "r" causes remeshing of the mesh volume - if not present the mesh surface is extracted and used for the volume mesh generation. 2. "q[<float>/<float>]" (required) - the two numbers after "q" are a maximum radius-edge ratio bound and a minimum dihedral angle bound. 3. "a<float>" (optional) - the number imposes a maximum volume constraint on all tetrahedra. 4. O[<0-9>/<0-7>] - the two numbers correspond to a mesh optimization level and a choice of optimizing operations. 5. "V" (optional) - if present, mesh statistics are printed. Consult the tetgen documentation for details.""", } def _parse_val_or_vec(option, name, parser): if option is not None: try: try: option = float(option) except ValueError: option = [float(ii) for ii in option.split(',')] option = nm.array(option, dtype=nm.float64, ndmin=1) except: output('bad %s! (%s)' % (name, option)) parser.print_help() sys.exit(1) return option def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('-s', '--scale', metavar='scale', action='store', dest='scale', default=None, help=helps['scale']) parser.add_argument('-c', '--center', metavar='center', action='store', dest='center', default=None, help=helps['center']) parser.add_argument('-r', '--refine', metavar='level', action='store', type=int, dest='refine', default=0, help=helps['refine']) parser.add_argument('-f', '--format', metavar='format', action='store', type=str, dest='format', default=None, help=helps['format']) parser.add_argument('-l', '--list', action='store_true', dest='list', help=helps['list']) parser.add_argument('-m', '--merge', action='store_true', dest='merge', help=helps['merge']) parser.add_argument('-t', '--tri-tetra', action='store_true', dest='tri_tetra', help=helps['tri-tetra']) parser.add_argument('-2', '--2d', action='store_true', dest='force_2d', help=helps['2d']) parser.add_argument('--save-per-mat', action='store_true', dest='save_per_mat', help=helps['save-per-mat']) parser.add_argument('--remesh', metavar='options', action='store', dest='remesh', default=None, help=helps['remesh']) parser.add_argument('filename_in') parser.add_argument('filename_out') options = parser.parse_args() if options.list: output('Supported readable mesh formats:') output('--------------------------------') output_mesh_formats('r') output('') output('Supported writable mesh formats:') output('--------------------------------') output_mesh_formats('w') sys.exit(0) scale = _parse_val_or_vec(options.scale, 'scale', parser) center = _parse_val_or_vec(options.center, 'center', parser) filename_in = options.filename_in filename_out = options.filename_out if options.remesh: import tempfile import shlex import subprocess dirname = tempfile.mkdtemp() is_surface = options.remesh.startswith('q') if is_surface: mesh = Mesh.from_file(filename_in) domain = FEDomain(mesh.name, mesh) region = domain.create_region('surf', 'vertices of surface', 'facet') surf_mesh = Mesh.from_region(region, mesh, localize=True, is_surface=True) filename = op.join(dirname, 'surf.mesh') surf_mesh.write(filename, io='auto') else: import shutil shutil.copy(filename_in, dirname) filename = op.join(dirname, op.basename(filename_in)) qopts = ''.join(options.remesh.split()) # Remove spaces. command = 'tetgen -BFENkACp%s %s' % (qopts, filename) args = shlex.split(command) subprocess.call(args) root, ext = op.splitext(filename) mesh = Mesh.from_file(root + '.1.vtk') remove_files(dirname) else: mesh = Mesh.from_file(filename_in) if options.force_2d: data = list(mesh._get_io_data()) data[0] = data[0][:, :2] mesh = Mesh.from_data(mesh.name, *data) if scale is not None: if len(scale) == 1: tr = nm.eye(mesh.dim, dtype=nm.float64) * scale elif len(scale) == mesh.dim: tr = nm.diag(scale) else: raise ValueError('bad scale! (%s)' % scale) mesh.transform_coors(tr) if center is not None: cc = 0.5 * mesh.get_bounding_box().sum(0) shift = center - cc tr = nm.c_[nm.eye(mesh.dim, dtype=nm.float64), shift[:, None]] mesh.transform_coors(tr) if options.refine > 0: domain = FEDomain(mesh.name, mesh) output('initial mesh: %d nodes %d elements' % (domain.shape.n_nod, domain.shape.n_el)) for ii in range(options.refine):
output('refine %d...' % ii)
sfepy.base.base.output
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
42
Edit dataset card

Collection including luna-code/sfepy