[WIP] updating to netgen 6.2.2004 (was smesh windows problem)

This subforum is specifically to discuss packaging issues on different platforms (windows, mac, linux), and using different packaging systems (conda, etc...)
User avatar
looo
Posts: 3431
Joined: Mon Nov 11, 2013 5:29 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby looo » Sat May 02, 2020 9:59 am

wmayer wrote:
Tue Apr 28, 2020 8:44 am
An option might be to add an implementation of OCCGenerateMesh to NETGENPlugin_Mesher.cxx in order to reduce the amount of changes.
Ok, I tried to do that, but still get an error at runtime:

Code: Select all

/home/lo/miniconda3/envs/freecad/lib/./libNETGENPlugin.so.8.3: undefined symbol: _ZN6netgen15OCCGenerateMeshERNS_11OCCGeometryERSt10shared_ptrINS_4MeshEERNS_17MeshingParametersE
Traceback (most recent call last):
  File "<string>", line 41, in Initialize
I added a file "NETGENPlugin_interface.hxx" which provides the "OCCGenerateMesh" function for different netgen versions:
https://github.com/LaughlinResearch/SME ... f5d187f28f

Not sure if it is right to define the function in a header file.
wmayer
Site Admin
Posts: 16300
Joined: Thu Feb 19, 2009 10:32 am

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby wmayer » Sat May 02, 2020 11:14 am

Where do you get the latest netgen sources from?
User avatar
looo
Posts: 3431
Joined: Mon Nov 11, 2013 5:29 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby looo » Tue May 05, 2020 11:43 am

If it is ok, I am going to ask some basic c++ questions:

1. I need the OCCGenerateMesh function in 3 files. If I define this function in all 3 files I get multiple definitions (the cxx-files are compiled into one target). So what is the obvious way to define the function only in one file and use it in all 3 files.

2. Defining the function in a header file and including it in all the 3 cxx files also results in redefinition errors.

3. How to handle occparam? I found this in the netgen code:
https://github.com/NGSolve/netgen/blob/ ... L1952L1953

Code: Select all

DLL_HEADER extern OCCParameters occparam;
OCCParameters occparam;
I wonder what's the obvious way to define this interface function so that it is useable in any cxx file and to allow also the external function to be used if an older version of netgen is installed. Does specifying external function in a header file works?

My attempt to create the interface looked like this:

Code: Select all


#ifndef _NETGENPlugin_interface_HXX_
#define _NETGENPlugin_interface_HXX_


#include <occgeom.hpp>
#include <meshing.hpp>
#include <nglib.h>

namespace netgen {

#ifdef NEW_NETGEN_INTERFACE

int OCCGenerateMesh(OCCGeometry& geo, shared_ptr<netgen::Mesh>& mesh, netgen::MeshingParameters& params)
{
  geo.SetOCCParameters(netgen::occparam);
  auto result = geo.GenerateMesh(mesh, params);
  mesh->SetGeometry(geo);
  return result;
}
#else

#if NETGEN_VERSION >= NETGEN_VERSION_STRING(6,2)
       DLL_HEADER extern int OCCGenerateMesh(OCCGeometry&, shared_ptr<Mesh>&, MeshingParameters&);
#elif NETGEN_VERSION >= NETGEN_VERSION_STRING(6,0)
       DLL_HEADER extern int OCCGenerateMesh(OCCGeometry&, shared_ptr<Mesh>&, MeshingParameters&, int, int);
#elif NETGEN_VERSION >= NETGEN_VERSION_STRING(5,0)
       DLL_HEADER extern int OCCGenerateMesh(OCCGeometry&, Mesh*&, MeshingParameters&, int, int);
#else
       DLL_HEADER extern int OCCGenerateMesh(OCCGeometry&, Mesh*&, int, int, char*);
#endif

#endif
}

#endif
User avatar
looo
Posts: 3431
Joined: Mon Nov 11, 2013 5:29 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby looo » Tue May 05, 2020 4:51 pm

It works defining the function in one cxx file and only declare the function in the other files. The whole thing compiles now, but still there are some runtime errors. I have no debug build so the output might not help a lot.

Code: Select all

Thread 1 "freecad" received signal SIGSEGV, Segmentation fault.
...
(gdb) bt
#0  0x00007ffff4a49c01 in __GI___libc_free (mem=0x7fffffffb620) at malloc.c:3123
#1  0x00007ffff720b3a6 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
   from /home/lo/miniconda3/envs/freecad/bin/../lib/libFreeCADGui.so
#2  0x00007fff841c1261 in netgen::OCCGenerateMesh(netgen::OCCGeometry&, std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) () from /home/lo/miniconda3/envs/freecad/lib/./libNETGENPlugin.so.8.3
The function is pretty short, so it might be possible to see my mistake. Most likely it is related to pointer/reference usage here:

Code: Select all

int OCCGenerateMesh(OCCGeometry& geo, shared_ptr<Mesh>& mesh, MeshingParameters& params)
    {
      shared_ptr<OCCGeometry> geo_ptr(&geo);
      geo_ptr->SetOCCParameters(occparam);
      auto result = geo_ptr->GenerateMesh(mesh, params);
      mesh->SetGeometry(geo_ptr);
      return result;
    }
edit: is it possible that this way the shared pointer deletes the raw pointer which was passed by reference and this leads to the segmentation fault?

edit1: Adding a custom deleter like it is shown in [1] works. But now there is still another problem. Every second time a mesh is created freecad crashes.

Code: Select all

#0  0x00007ffff4ee7c2b in std::ostream::sentry::sentry (this=0x7fffffff9b80, __os=...)
    at /home/conda/feedstock_root/build_artifacts/ctng-compilers_1578638331887/work/.build/x86_64-conda_cos6-linux-gnu/build/build-cc-gcc-final/x86_64-conda_cos6-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:46
#1  0x00007ffff4ee8a7b in std::__ostream_insert<char, std::char_traits<char> > (__out=..., 
    __s=0x7fff26cacfdd "edge meshing", __n=12)
    at /home/conda/feedstock_root/build_artifacts/ctng-compilers_1578638331887/work/.build/x86_64-conda_cos6-linux-gnu/build/build-cc-gcc-final/x86_64-conda_cos6-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:76
#2  0x00007fff26c6534e in netgen::OCCFindEdges(netgen::OCCGeometry const&, netgen::Mesh&, netgen::MeshingParameters const&) () from /home/lo/miniconda3/envs/freecad/lib/././libocc.so
#3  0x00007fff26ee70a5 in netgen::NetgenGeometry::GenerateMesh(std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) () from /home/lo/miniconda3/envs/freecad/lib/././libmesh.so
#4  0x00007fff8412c29e in netgen::OCCGenerateMesh(netgen::OCCGeometry&, std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) () from /home/lo/miniconda3/envs/freecad/lib/./libNETGENPlugin.so.8.3
[1] https://stackoverflow.com/a/57497604
User avatar
looo
Posts: 3431
Joined: Mon Nov 11, 2013 5:29 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby looo » Wed May 06, 2020 7:58 am

Would be nice if anyone with a debug build is able to debug the current state. This are the steps to reproduce:

1. build netgen6.2.2004: https://github.com/NGSolve/netgen/tree/v6.2.2004
2. build smesh with my patches: https://github.com/looooo/SMESH/tree/netgen6.2.2004

additional you need to build freecad with external smesh enabled.
User avatar
sgrogan
Posts: 5969
Joined: Wed Oct 22, 2014 5:02 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby sgrogan » Wed May 06, 2020 10:02 pm

looo wrote:
Wed May 06, 2020 7:58 am
Would be nice if anyone with a debug build is able to debug the current state. This are the steps to reproduce:
I will try.
I'm using this as an inspiration https://github.com/conda-forge/netgen-f ... pe/bld.bat
I was able to build netgen with default netgen cmake. This is a superbuild without occ. It by default gives RelWithDebInfo even with Debug build in the VS IDE.
If I use occ cmake wants to download the netgen deps. So I disable superbuid.
It goes sideways here. I will need to bang away in the CMake gui.

I assume I need debug debug of nglib, then eventually debug build of external Smesh, and finally a debug FreeCAD linked against these?

EDIT: One more question is the OCC version important? 7.3 vs 7.4. If it is I will need to build a debug occ 7.4 to link ng to.
User avatar
looo
Posts: 3431
Joined: Mon Nov 11, 2013 5:29 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby looo » Wed May 06, 2020 10:38 pm

Thanks @sgrogan.
EDIT: One more question is the OCC version important? 7.3 vs 7.4. If it is I will need to build a debug occ 7.4 to link ng to.
No I don't think the off version is important.
User avatar
sgrogan
Posts: 5969
Joined: Wed Oct 22, 2014 5:02 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby sgrogan » Wed May 06, 2020 10:39 pm

looo wrote:
Wed May 06, 2020 10:38 pm
No I don't think the off version is important.
OK, I will try to link against the debug versions in the Libpack (12.1.2)
User avatar
looo
Posts: 3431
Joined: Mon Nov 11, 2013 5:29 pm

Re: [WIP] updating to netgen 6.2.2004 (was smesh windows problem)

Postby looo » Thu May 07, 2020 6:29 am

Is it necessary to have the source code available for RelWithDebInfo packages? If not, it should be possible to create debug packages of some of the dependencies. If it is easy to strip the debug symbols it should be possible to create special optional debug-packages.