1D meshes

This commit is contained in:
Joachim Schöberl 2015-08-31 17:41:26 +02:00
parent 507b370a6f
commit 570d81c8cb
2 changed files with 47 additions and 8 deletions

View File

@ -608,6 +608,32 @@ namespace netgen
}
template <>
DLL_HEADER int Ngx_Mesh :: FindElementOfPoint <1>
(double * hp, double * lami,
bool build_searchtree,
int * const indices, int numind) const
{
if (mesh->GetDimension() != 1)
throw NgException("FindElementOfPoint<1> called for multidim mesh");
Point<3> p(hp[0], 0,0);
for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
{
auto & seg = (*mesh)[si];
Point<3> p1 = (*mesh)[seg[0]];
Point<3> p2 = (*mesh)[seg[1]];
double lam = (p(0)-p1(0)) / (p2(0)-p1(0));
if (lam >= -1e-10 && lam <= 1+1e-10)
{
lami[0] = 1-lam;
return si;
}
}
return -1;
}
template <>
DLL_HEADER int Ngx_Mesh :: FindElementOfPoint <2>
(double * p, double * lami,

View File

@ -158,18 +158,24 @@ DLL_HEADER void ExportNetgenMeshing()
bp::class_<Segment>("Element1D")
.def("__init__", bp::make_constructor
(FunctionPointer ([](bp::list vertices, bp::list surfaces)
(FunctionPointer ([](bp::list vertices, bp::list surfaces, int index)
{
Segment * tmp = new Segment;
for (int i = 0; i < 2; i++)
(*tmp)[i] = bp::extract<PointIndex>(vertices[i]);
tmp -> si = index;
if (len(surfaces))
{
tmp->surfnr1 = bp::extract<int>(surfaces[0]);
tmp->surfnr2 = bp::extract<int>(surfaces[1]);
}
return tmp;
}),
bp::default_call_policies(),
(bp::arg("vertices"),bp::arg("surfaces"))),
(bp::arg("vertices"),
bp::arg("surfaces")=bp::list(),
bp::arg("index")=1
)),
"create segment element"
)
.def("__repr__", &ToString<Element>)
@ -233,11 +239,16 @@ DLL_HEADER void ExportNetgenMeshing()
.def("Load", FunctionPointer
([](Mesh & self, const string & filename)
{
ifstream input(filename);
self.Load(input);
istream * infile;
if (filename.find(".vol.gz") != string::npos)
infile = new igzstream (filename.c_str());
else
infile = new ifstream (filename.c_str());
// ifstream input(filename);
self.Load(*infile);
for (int i = 0; i < geometryregister.Size(); i++)
{
NetgenGeometry * hgeom = geometryregister[i]->LoadFromMeshFile (input);
NetgenGeometry * hgeom = geometryregister[i]->LoadFromMeshFile (*infile);
if (hgeom)
{
ng_geometry.reset (hgeom);
@ -248,6 +259,8 @@ DLL_HEADER void ExportNetgenMeshing()
// static_cast<void(Mesh::*)(const string & name)>(&Mesh::Load))
.def("Save", static_cast<void(Mesh::*)(const string & name)const>(&Mesh::Save))
.add_property("dim", &Mesh::GetDimension, &Mesh::SetDimension)
.def("Elements3D",
static_cast<Array<Element>&(Mesh::*)()> (&Mesh::VolumeElements),
bp::return_value_policy<bp::reference_existing_object>())