diff -Nru ngsolve-6.2.1810/basiclinalg/matrix.hpp ngsolve-6.2.1901/basiclinalg/matrix.hpp --- ngsolve-6.2.1810/basiclinalg/matrix.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/basiclinalg/matrix.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -543,6 +543,7 @@ /// fill matrix with scalar Matrix & operator= (const Matrix & m2) { + SetSize (m2.Height(), m2.Width()); FlatMatrix::operator= (m2); return *this; } @@ -667,6 +668,10 @@ return FixSliceVector (H, &(*this)(0,i)); } + void DoArchive(Archive& ar) + { + ar.Do(&data[0], H*W); + } }; template diff -Nru ngsolve-6.2.1810/basiclinalg/ngblas.cpp ngsolve-6.2.1901/basiclinalg/ngblas.cpp --- ngsolve-6.2.1810/basiclinalg/ngblas.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/basiclinalg/ngblas.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -75,7 +75,7 @@ if (i+1 <= h) { - auto scal = MatKernelScalAB<2,1> (w, pa, a.Dist(), &x(0), 0); + auto scal = MatKernelScalAB<1,1> (w, pa, a.Dist(), &x(0), 0); y(i) = get<0>(scal); } @@ -1979,7 +1979,7 @@ /**************** timings *********************** */ - list> Timing (int what, size_t n, size_t m, size_t k) + list> Timing (int what, size_t n, size_t m, size_t k, bool lapack) { if (what < 0) { @@ -2142,7 +2142,8 @@ double tot = n*m*k; int its = 1e10 / tot + 1; - MultMatMat(a,b,c); + // MultMatMat(a,b,c); + c = a * b; double err = L2Norm(a*b-c); if (err > 1e-8) throw Exception("MultMatMat is faulty"); @@ -2150,8 +2151,13 @@ { Timer t("C = A*B"); t.Start(); - for (int j = 0; j < its; j++) - MultMatMat(a,b,c); + if (!lapack) + for (int j = 0; j < its; j++) + // MultMatMat(a,b,c); + c = a*b; + else + for (int j = 0; j < its; j++) + c = a*b | Lapack; t.Stop(); cout << "MultMatMat GFlops = " << 1e-9 * n*m*k*its / t.GetTime() << endl; timings.push_back(make_tuple("MultMatMat", 1e-9 * n*m*k*its / t.GetTime())); @@ -2170,7 +2176,8 @@ Timer t("C = A*B"); t.Start(); for (int j = 0; j < its; j++) - AddABt(a,b,c); + // AddABt(a,b,c); + c += a * Trans(b); t.Stop(); cout << "AddABt GFlops = " << 1e-9 * tot*its / t.GetTime() << endl; timings.push_back(make_tuple("AddABt", 1e-9 * tot *its / t.GetTime())); @@ -2214,8 +2221,12 @@ { Timer t("C = A*B"); t.Start(); - for (int j = 0; j < its; j++) - c = a * Trans(b); + if (!lapack) + for (int j = 0; j < its; j++) + c = a * Trans(b); + else + for (int j = 0; j < its; j++) + c = a * Trans(b) | Lapack; t.Stop(); cout << "AddABt GFlops = " << 1e-9 * tot*its / t.GetTime() << endl; timings.push_back(make_tuple("AddABt", 1e-9 * tot *its / t.GetTime())); diff -Nru ngsolve-6.2.1810/basiclinalg/ngblas.hpp ngsolve-6.2.1901/basiclinalg/ngblas.hpp --- ngsolve-6.2.1810/basiclinalg/ngblas.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/basiclinalg/ngblas.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -348,7 +348,7 @@ } - extern list> Timing (int what, size_t n, size_t m, size_t k); + extern list> Timing (int what, size_t n, size_t m, size_t k, bool lapack); } diff -Nru ngsolve-6.2.1810/basiclinalg/python_bla.cpp ngsolve-6.2.1901/basiclinalg/python_bla.cpp --- ngsolve-6.2.1810/basiclinalg/python_bla.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/basiclinalg/python_bla.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -85,6 +85,7 @@ c.def("__sub__" , [](T &self, T &v) { return TNEW(self-v); }, py::arg("vec") ); c.def("__mul__" , [](T &self, TSCAL s) { return TNEW(s*self); }, py::arg("value") ); c.def("__rmul__" , [](T &self, TSCAL s) { return TNEW(s*self); }, py::arg("value") ); + c.def("__neg__" , [](T &self) { return TNEW(-self); }); c.def("InnerProduct", [](T & x, T & y) { return InnerProduct (x, y); }, py::arg("y"), "Returns InnerProduct with other object"); c.def("Norm", [](T & x) { return L2Norm(x); }, "Returns L2-norm"); } @@ -312,6 +313,7 @@ c.def("__mul__" , [](TMAT &self, FlatVector &v) { return Vector(self*v); }, py::arg("vec") ); c.def("__mul__" , [](TMAT &self, TSCAL s) { return TNEW(s*self); }, py::arg("values") ); c.def("__rmul__" , [](TMAT &self, TSCAL s) { return TNEW(s*self); }, py::arg("value") ); + c.def("__neg__" , [](TMAT &self) { return TNEW(-self); }); c.def("Height", &TMAT::Height, "Return height of matrix" ); c.def("Width", &TMAT::Width, "Return width of matrix" ); c.def_property_readonly("h", py::cpp_function(&TMAT::Height ), "Height of the matrix"); @@ -571,7 +573,7 @@ [] (py::object x) -> py::object { return py::object(x.attr("Norm")) (); }, py::arg("x"),"Compute Norm"); - m.def("__timing__", &ngbla::Timing); + m.def("__timing__", &ngbla::Timing, py::arg("what"), py::arg("n"), py::arg("m"), py::arg("k"), py::arg("lapack")=false); m.def("CheckPerformance", [] (size_t n, size_t m, size_t k) { diff -Nru ngsolve-6.2.1810/cmake/SuperBuild.cmake ngsolve-6.2.1901/cmake/SuperBuild.cmake --- ngsolve-6.2.1810/cmake/SuperBuild.cmake 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/cmake/SuperBuild.cmake 2019-01-12 00:18:33.000000000 +0000 @@ -93,6 +93,7 @@ INTEL_MIC USE_CCACHE USE_NATIVE_ARCH + ENABLE_UNIT_TESTS ) set_flags_vars(NETGEN_CMAKE_ARGS CMAKE_CXX_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_LINKER_FLAGS) ExternalProject_Add (netgen_project diff -Nru ngsolve-6.2.1810/CMakeLists.txt ngsolve-6.2.1901/CMakeLists.txt --- ngsolve-6.2.1810/CMakeLists.txt 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/CMakeLists.txt 2019-01-12 00:18:33.000000000 +0000 @@ -44,6 +44,8 @@ set(INSTALL_DIR_DEFAULT ${INSTALL_DIR}) endif(INSTALL_DIR) +set(CMAKE_CXX_STANDARD 17) + if (USE_SUPERBUILD) project (NGSuite) if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) diff -Nru ngsolve-6.2.1810/comp/bilinearform.cpp ngsolve-6.2.1901/comp/bilinearform.cpp --- ngsolve-6.2.1810/comp/bilinearform.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/bilinearform.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -549,7 +549,8 @@ if (nonassemble) { - mats.Append (make_shared (shared_ptr(this, NOOP_Deleter))); + // mats.Append (make_shared (shared_ptr(this, NOOP_Deleter)), lh); + mats.Append (make_shared (dynamic_pointer_cast(this->shared_from_this()), lh)); if (precompute) { @@ -723,7 +724,13 @@ GalerkinProjection(); } - + shared_ptr BilinearForm :: GetMatrixPtr () const + { + if (!mats.Size()) + return nullptr; + return mats.Last(); + } + void BilinearForm :: PrintReport (ostream & ost) const { @@ -864,7 +871,7 @@ IterateElements (*fespace,vb,clh, [&] (FESpace::Element el, LocalHeap & lh) { - if(bfi->DefinedOn(el.GetIndex())) + if(bfi->DefinedOn(el.GetIndex()) && bfi->DefinedOnElement(el.Nr())) bfi->CheckElement(el.GetFE()); }); if(bfi->VB()==VOL && bfi->SkeletonForm()) @@ -1035,15 +1042,12 @@ if (fel.GetNDof() != dnums.Size()) { - cout << "fel:GetNDof() = " << fel.GetNDof() << endl; - cout << "dnums.Size() = " << dnums.Size() << endl; - *testout << "Info from finite element: " << endl; fel.Print (*testout); - (*testout) << "fel:GetNDof() = " << fel.GetNDof() << endl; + (*testout) << "fel::GetNDof() = " << fel.GetNDof() << endl; (*testout) << "dnums.Size() = " << dnums.Size() << endl; (*testout) << "dnums = " << dnums << endl; - throw Exception ( "Inconsistent number of degrees of freedom " ); + throw Exception ( string("Inconsistent number of degrees of freedom fel::GetNDof() = ") + ToString(fel.GetNDof()) + string(" != dnums.Size() = ") + ToString(dnums.Size()) + string("!") ); } int elmat_size = dnums.Size()*fespace->GetDimension(); @@ -1815,13 +1819,10 @@ fespace->GetDofNrs (ei1, dnums); if(fel.GetNDof() != dnums.Size()) { - cout << "Surface fel:GetNDof() = " << fel.GetNDof() << endl; - cout << "dnums.Size() = " << dnums.Size() << endl; - - (*testout) << "fel:GetNDof() = " << fel.GetNDof() << endl; + (*testout) << "Surface fel::GetNDof() = " << fel.GetNDof() << endl; (*testout) << "dnums.Size() = " << dnums.Size() << endl; (*testout) << "dnums = " << dnums << endl; - throw Exception ( "Inconsistent number of degrees of freedom " ); + throw Exception ( string("Inconsistent number of degrees of freedom Surface fel::GetNDof() = ") + ToString(fel.GetNDof()) + string(" != dnums.Size() = ") + ToString(dnums.Size()) + string("!") ); } /* @@ -2087,13 +2088,10 @@ fespace->GetDofNrs (ei, dnums); if(fel.GetNDof() != dnums.Size()) { - cout << "Surface fel:GetNDof() = " << fel.GetNDof() << endl; - cout << "dnums.Size() = " << dnums.Size() << endl; - - (*testout) << "fel:GetNDof() = " << fel.GetNDof() << endl; + (*testout) << "Surface fel::GetNDof() = " << fel.GetNDof() << endl; (*testout) << "dnums.Size() = " << dnums.Size() << endl; (*testout) << "dnums = " << dnums << endl; - throw Exception ( "Inconsistent number of degrees of freedom " ); + throw Exception ( string("Inconsistent number of degrees of freedom Surface fel::GetNDof() = ") + ToString(fel.GetNDof()) + string(" != dnums.Size() = ") + ToString(dnums.Size()) + string("!") ); } /* @@ -2327,6 +2325,9 @@ FlatMatrix elmat(dnums2.Size(), dnums1.Size(), lh); for (auto & bfi : VB_parts[VOL]) { + if (!bfi->DefinedOn (eltrans.GetElementIndex())) continue; + if (!bfi->DefinedOnElement (ei.Nr())) continue; + MixedFiniteElement fel(fel1, fel2); bfi->CalcElementMatrix (fel, eltrans, elmat, lh); /* @@ -2680,10 +2681,11 @@ if(fel.GetNDof() != dnums.Size()) { - cout << "fel::GetNDof() = " << fel.GetNDof() << endl; - cout << "dnums.Size() = " << dnums.Size() << endl; + (*testout) << "fel::GetNDof() = " << fel.GetNDof() << endl; + (*testout) << "dnums.Size() = " << dnums.Size() << endl; + (*testout) << "dnums = " << dnums << endl; + throw Exception ( string("Inconsistent number of degrees of freedom fel::GetNDof() = ") + ToString(fel.GetNDof()) + string(" != dnums.Size() = ") + ToString(dnums.Size()) + string("!") ); } - for (auto d : dnums) if (IsRegularDof(d)) useddof[d] = true; @@ -2997,13 +2999,10 @@ fespace->GetDofNrs (ei, dnums); if(fel.GetNDof() != dnums.Size()) { - cout << "Surface fel:GetNDof() = " << fel.GetNDof() << endl; - cout << "dnums.Size() = " << dnums.Size() << endl; - - (*testout) << "fel:GetNDof() = " << fel.GetNDof() << endl; + (*testout) << "Surface fel::GetNDof() = " << fel.GetNDof() << endl; (*testout) << "dnums.Size() = " << dnums.Size() << endl; (*testout) << "dnums = " << dnums << endl; - throw Exception ( "Inconsistent number of degrees of freedom " ); + throw Exception ( string("Inconsistent number of degrees of freedom Surface fel::GetNDof() = ") + ToString(fel.GetNDof()) + string(" != dnums.Size() = ") + ToString(dnums.Size()) + string("!") ); } /* @@ -3844,13 +3843,11 @@ fespace->GetDofNrs (ei1, dnums); if(fel.GetNDof() != dnums.Size()) { - cout << "Surface fel:GetNDof() = " << fel.GetNDof() << endl; - cout << "dnums.Size() = " << dnums.Size() << endl; - - (*testout) << "fel:GetNDof() = " << fel.GetNDof() << endl; + + (*testout) << "fel::GetNDof() = " << fel.GetNDof() << endl; (*testout) << "dnums.Size() = " << dnums.Size() << endl; (*testout) << "dnums = " << dnums << endl; - throw Exception ( "Inconsistent number of degrees of freedom " ); + throw Exception ( string("Inconsistent number of degrees of freedom Surface fel::GetNDof() = ") + ToString(fel.GetNDof()) + string(" != dnums.Size() = ") + ToString(dnums.Size()) + string("!") ); } @@ -4155,6 +4152,7 @@ for (auto & bfi : VB_parts[vb]) { if (!bfi->DefinedOn (this->ma->GetElIndex (ei))) continue; + if (!bfi->DefinedOnElement (ei.Nr())) continue; MixedFiniteElement fel(fel1, fel2); bfi->ApplyElementMatrix (fel, eltrans, elvecx, elvecy, 0, lh); @@ -4186,7 +4184,8 @@ // classify: auto fesx = GetTrialSpace(); - auto fesy = GetTestSpace(); + auto fesy = GetTestSpace(); + if (transpose) Swap (fesx, fesy); auto ma = GetMeshAccess(); Array classnr(ma->GetNE()); @@ -4208,19 +4207,97 @@ for (auto elclass_inds : table) { if (elclass_inds.Size() == 0) continue; - + + /* ElementId ei(VOL,elclass_inds[0]); - auto & felx = fesx->GetFE (ei, lh); - auto & fely = fesy->GetFE (ei, lh); - auto & trafo = fesx->GetMeshAccess()->GetTrafo(ei, lh); + auto & felx = GetTrialSpace()->GetFE (ei, lh); + auto & fely = GetTestSpace()->GetFE (ei, lh); + auto & trafo = GetTrialSpace()->GetMeshAccess()->GetTrafo(ei, lh); MixedFiniteElement fel(felx, fely); Matrix<> elmat(fely.GetNDof(), felx.GetNDof()); - elmat = 0.0; - for (auto bfi : geom_free_parts) - bfi->CalcElementMatrixAdd(fel, trafo, elmat, lh); + size_t nr = classnr[elclass_inds[0]]; + if (precomputed.count(nr)) + { + elmat = precomputed[nr]; + } + else + { + elmat = 0.0; + for (auto bfi : geom_free_parts) + bfi->CalcElementMatrixAdd(fel, trafo, elmat, lh); + + precomputed[nr] = Matrix<>(fely.GetNDof(), felx.GetNDof()); + precomputed[nr] = elmat; + } + */ + + + size_t nr = classnr[elclass_inds[0]]; + if (precomputed.count(nr) == 0) + { + ElementId ei(VOL,elclass_inds[0]); + auto & felx = GetTrialSpace()->GetFE (ei, lh); + auto & fely = GetTestSpace()->GetFE (ei, lh); + auto & trafo = GetTrialSpace()->GetMeshAccess()->GetTrafo(ei, lh); + MixedFiniteElement fel(felx, fely); + + Matrix<> elmat(fely.GetNDof(), felx.GetNDof()); + elmat = 0.0; + + for (auto bfi : geom_free_parts) + bfi->CalcElementMatrixAdd(fel, trafo, elmat, lh); + + // precomputed[nr] = Matrix<>(fely.GetNDof(), felx.GetNDof()); + precomputed[nr] = move(elmat); + } + + Matrix<> elmat = precomputed[nr]; elmat *= ConvertTo (val); // only real factor supported by now - + + Matrix<> temp_x(elclass_inds.Size(), !transpose ? elmat.Width() : elmat.Height()); + Matrix<> temp_y(elclass_inds.Size(), !transpose ? elmat.Height() : elmat.Width()); + + ParallelForRange + (Range(elclass_inds), + [&] (IntRange myrange) + { + Array dofs; + + int tid = TaskManager::GetThreadId(); + { + ThreadRegionTimer r(tx, tid); + auto fvx = x.FVDouble(); + for (auto i : myrange) + { + fesx->GetDofNrs(ElementId(VOL,elclass_inds[i]), dofs); + x.GetIndirect(dofs, temp_x.Row(i)); + } + } + + { + ThreadRegionTimer r(tm,tid); + RegionTracer rt(tid, tm); + NgProfiler::AddThreadFlops(tm, tid, elmat.Height()*elmat.Width()*myrange.Size()); + if (!transpose) + temp_y.Rows(myrange) = temp_x.Rows(myrange) * Trans(elmat); + else + temp_y.Rows(myrange) = temp_x.Rows(myrange) * elmat; + } + { + ThreadRegionTimer r(ty,tid); + for (auto i : myrange) + { + fesy->GetDofNrs(ElementId(VOL,elclass_inds[i]), dofs); + y.AddIndirect(dofs, temp_y.Row(i), true); + // todo: check if atomic is actually needed for space + } + } + }); + + + + /* Matrix<> temp_x(elclass_inds.Size(), elmat.Width()); Matrix<> temp_y(elclass_inds.Size(), elmat.Height()); @@ -4245,6 +4322,7 @@ { ThreadRegionTimer r(tm,tid); + RegionTracer rt(tid, tm); NgProfiler::AddThreadFlops(tm, tid, elmat.Height()*elmat.Width()*myrange.Size()); temp_y.Rows(myrange) = temp_x.Rows(myrange) * Trans(elmat); } @@ -4288,6 +4366,7 @@ } }); } + */ } } @@ -4348,7 +4427,7 @@ if (bfi.BoundaryForm()) continue; if (!bfi.DefinedOn (ma->GetElIndex (ei))) continue; - + if (!bfi.DefinedOnElement(ei.Nr())) continue; bfi.ApplyLinearizedElementMatrix (fel, eltrans, elveclin, elvecx, elvecy, lh); @@ -4385,6 +4464,7 @@ if (!bfi.BoundaryForm()) continue; if (!bfi.DefinedOn (eltrans.GetElementIndex())) continue; + if (!bfi.DefinedOnElement(sei.Nr())) continue; bfi.ApplyLinearizedElementMatrix (fel, eltrans, elveclin, elvecx, elvecy, lh); fespace->TransformVec (sei, elvecy, TRANSFORM_RHS); @@ -4453,6 +4533,7 @@ for (auto & bfi : VB_parts[vb]) { if (!bfi->DefinedOn (ei.GetIndex())) continue; + if (!bfi->DefinedOnElement(ei.Nr())) continue; energy_T += bfi->Energy (fel, eltrans, elvecx, lh); } @@ -5416,8 +5497,9 @@ BilinearFormApplication :: - BilinearFormApplication (shared_ptr abf) - : bf (abf) + BilinearFormApplication (shared_ptr abf, + LocalHeap & alh) + : bf (abf), lh(alh) { ; } @@ -5425,10 +5507,13 @@ void BilinearFormApplication :: Mult (const BaseVector & v, BaseVector & prod) const { + static Timer t("BilinearFormApplication"); RegionTimer r(t); v.Cumulate(); prod = 0; + bf -> AddMatrix (1, v, prod, lh); + /* bool done = false; static int lh_size = 10*1000*1000; @@ -5436,7 +5521,7 @@ { try { - LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); + // LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); bf -> AddMatrix (1, v, prod, lh); done = true; } @@ -5446,7 +5531,8 @@ cerr << "Trying automatic heapsize increase to " << lh_size << endl; } } - + */ + prod.SetParallelStatus (DISTRIBUTED); } @@ -5456,8 +5542,8 @@ v.Cumulate(); prod.Distribute(); - // bf -> AddMatrix (val, v, prod); - + bf -> AddMatrix (val, v, prod, lh); + /* bool done = false; static int lh_size = 10*1000*1000; @@ -5465,7 +5551,8 @@ { try { - LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); + static Timer t("BilinearFormApplication"); RegionTimer r(t); + // LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); bf -> AddMatrix (val, v, prod, lh); done = true; } @@ -5475,6 +5562,7 @@ cerr << "Trying automatic heapsize increase to " << lh_size << endl; } } + */ } @@ -5484,8 +5572,8 @@ v.Cumulate(); prod.Distribute(); - // bf -> AddMatrix (val, v, prod); - + bf -> AddMatrix (val, v, prod, lh); + /* bool done = false; static int lh_size = 10*1000*1000; @@ -5493,7 +5581,7 @@ { try { - LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); + // LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); bf -> AddMatrix (val, v, prod, lh); done = true; } @@ -5503,7 +5591,7 @@ cerr << "Trying automatic heapsize increase to " << lh_size << endl; } } - + */ } void BilinearFormApplication :: @@ -5512,8 +5600,8 @@ v.Cumulate(); prod.Distribute(); - // bf -> AddMatrix (val, v, prod); - + bf -> AddMatrixTrans (val, v, prod, lh); + /* bool done = false; static int lh_size = 10*1000*1000; @@ -5521,7 +5609,7 @@ { try { - LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); + // LocalHeap lh(lh_size*TaskManager::GetMaxThreads(), "biform-AddMatrix - Heap"); bf -> AddMatrixTrans (val, v, prod, lh); done = true; } @@ -5531,7 +5619,7 @@ cerr << "Trying automatic heapsize increase to " << lh_size << endl; } } - + */ } shared_ptr CreateBilinearForm (shared_ptr space, @@ -5585,8 +5673,9 @@ LinearizedBilinearFormApplication :: LinearizedBilinearFormApplication (shared_ptr abf, - const BaseVector * aveclin) - : BilinearFormApplication (abf), veclin(aveclin) + const BaseVector * aveclin, + LocalHeap & alh) + : BilinearFormApplication (abf, alh), veclin(aveclin) { ; } diff -Nru ngsolve-6.2.1810/comp/bilinearform.hpp ngsolve-6.2.1901/comp/bilinearform.hpp --- ngsolve-6.2.1810/comp/bilinearform.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/bilinearform.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -106,7 +106,8 @@ Array precomputed_data; /// output of norm of matrix entries bool checksum; - + + mutable std::map> precomputed; public: /// generate a bilinear-form BilinearForm (shared_ptr afespace, @@ -238,11 +239,7 @@ const BaseMatrix & GetMatrix () const { return *mats.Last(); } const BaseMatrix & GetMatrix (int level) const { return *mats[level]; } /// returns the assembled matrix - shared_ptr GetMatrixPtr () const - { - if (!mats.Size()) return nullptr; - return mats.Last(); - } + shared_ptr GetMatrixPtr () const; // operator const BaseMatrix& () const { return GetMatrix(); } @@ -321,6 +318,7 @@ /// don't assemble the matrix void SetNonAssemble (bool na = true) { nonassemble = na; } + bool NonAssemble() const { return nonassemble; } /// void SetGalerkin (bool agalerkin = true) { galerkin = agalerkin; } @@ -892,10 +890,10 @@ protected: /// shared_ptr bf; - + LocalHeap & lh; public: /// - BilinearFormApplication (shared_ptr abf); + BilinearFormApplication (shared_ptr abf, LocalHeap & alh); virtual bool IsComplex() const override { @@ -941,7 +939,8 @@ public: /// LinearizedBilinearFormApplication (shared_ptr abf, - const BaseVector * aveclin); + const BaseVector * aveclin, + LocalHeap & alh); /// using BilinearFormApplication::Mult; diff -Nru ngsolve-6.2.1810/comp/fespace.cpp ngsolve-6.2.1901/comp/fespace.cpp --- ngsolve-6.2.1810/comp/fespace.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/fespace.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -2001,6 +2001,10 @@ } else { + evaluator[VOL] = make_shared>>(); + flux_evaluator[VOL] = make_shared>>(); + evaluator[BND] = make_shared>>(); + integrator[VOL].reset (new MassIntegrator<3> (new ConstantCoefficientFunction(1))); integrator[BND].reset (new RobinIntegrator<3> (new ConstantCoefficientFunction(1))); } @@ -2019,17 +2023,40 @@ FiniteElement & NonconformingFESpace :: GetFE (ElementId ei, Allocator & lh) const { + if (ei.IsVolume()) + { + switch (ma->GetElType(ei)) + { + case ET_TRIG: return *(new (lh) FE_NcTrig1); + case ET_TET: return *(new (lh) FE_NcTet1); + default: throw Exception ("Element type not available in NonconformingFESpace::GetFE, vol"); + } + } + + if (ei.IsBoundary()) + { + switch (ma->GetElType(ei)) + { + case ET_SEGM: return *(new (lh) FE_Segm0); + case ET_TRIG: return *(new (lh) FE_Trig0); + default: throw Exception ("Element type not available in NonconformingFESpace::GetFE, bnd"); + } + } + throw Exception ("NonconormingFE: only vol or bnd"); + /* switch (ma->GetElType(ei)) { case ET_TRIG: return *(new (lh) FE_NcTrig1); case ET_SEGM: return *(new (lh) FE_Segm0); default: throw Exception ("Element type not available in NonconformingFESpace::GetFE"); } + */ } size_t NonconformingFESpace :: GetNDof () const throw() { - return ma->GetNEdges(); + // return ma->GetNEdges(); + return ma->GetNFacets(); } @@ -2089,7 +2116,8 @@ void NonconformingFESpace :: GetDofNrs (ElementId ei, Array & dnums) const { - dnums = ma->GetElEdges(ei); + // dnums = ma->GetElEdges(ei); + dnums = ma->GetElFacets(ei); if (!DefinedOn(ei)) dnums = -1; } @@ -2913,6 +2941,69 @@ + + InverseMass :: InverseMass (shared_ptr afes, + shared_ptr arho, + LocalHeap & alh) + : fes(afes), rho(arho), lh(alh) { ; } + + InverseMass :: ~InverseMass() + { ; } + + + + void InverseMass :: Mult (const BaseVector & v, BaseVector & prod) const + { + prod = v; + fes->SolveM(rho.get(), prod, lh); + } + + void InverseMass :: MultAdd (double val, const BaseVector & v, BaseVector & prod) const + { + auto hv = prod.CreateVector(); + hv = v; + fes->SolveM(rho.get(), hv, lh); + prod += val * hv; + } + + void InverseMass :: MultAdd (Complex val, const BaseVector & v, BaseVector & prod) const + { + auto hv = prod.CreateVector(); + hv = v; + fes->SolveM(rho.get(), hv, lh); + prod += val * hv; + } + + void InverseMass :: MultTransAdd (double val, const BaseVector & v, BaseVector & prod) const + { + MultAdd (val, v, prod); + } + + AutoVector InverseMass :: CreateVector () const + { + // should go to fespace + return CreateBaseVector(fes->GetNDof(), fes->IsComplex(), fes->GetDimension()); + } + + AutoVector InverseMass :: CreateRowVector () const + { + // should go to fespace + return CreateBaseVector(fes->GetNDof(), fes->IsComplex(), fes->GetDimension()); + } + + AutoVector InverseMass :: CreateColVector () const + { + // should go to fespace + return CreateBaseVector(fes->GetNDof(), fes->IsComplex(), fes->GetDimension()); + } + + + + + + + + Table Nodes2Table (const MeshAccess & ma, const Array & dofnodes) { diff -Nru ngsolve-6.2.1810/comp/fespace.hpp ngsolve-6.2.1901/comp/fespace.hpp --- ngsolve-6.2.1810/comp/fespace.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/fespace.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -1193,6 +1193,43 @@ }; + class NGS_DLL_HEADER InverseMass : public BaseMatrix + { + protected: + shared_ptr fes; + shared_ptr rho; + LocalHeap & lh; + public: + /// + InverseMass (shared_ptr afes, + shared_ptr arho, + LocalHeap & alh); + virtual ~InverseMass(); + + virtual bool IsComplex() const override + { + return fes->IsComplex(); + } + + virtual void Mult (const BaseVector & v, BaseVector & prod) const override; + virtual void MultAdd (double val, const BaseVector & v, BaseVector & prod) const override; + virtual void MultAdd (Complex val, const BaseVector & v, BaseVector & prod) const override; + virtual void MultTransAdd (double val, const BaseVector & v, BaseVector & prod) const override; + + virtual AutoVector CreateVector () const override; + virtual AutoVector CreateRowVector () const override; + virtual AutoVector CreateColVector () const override; + + virtual int VHeight() const override + { + return fes->GetNDof(); + } + /// + virtual int VWidth() const override + { + return fes->GetNDof(); + } + }; diff -Nru ngsolve-6.2.1810/comp/gridfunction.cpp ngsolve-6.2.1901/comp/gridfunction.cpp --- ngsolve-6.2.1810/comp/gridfunction.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/gridfunction.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -311,13 +311,21 @@ } - shared_ptr GridFunction :: - GetComponent (int compound_comp) const + shared_ptr GridFunction :: + GetComponent (int compound_comp) { - if (!compgfs.Size() || compgfs.Size() < compound_comp) - throw Exception("GetComponent: compound_comp does not exist!"); - else - return compgfs[compound_comp]; + auto compfes = dynamic_pointer_cast(fespace); + if(compfes) + { + if (compound_comp >= compfes->GetNSpaces()) + throw Exception("GetComponent: compound_comp does not exist!"); + auto sptr = make_shared(dynamic_pointer_cast(this->shared_from_this()), + compound_comp); + compgfs.push_back(sptr); + sptr->Update(); + return sptr; + } + throw Exception("GetComponent: Not a GridFunction on a Compound FESpace!"); } @@ -780,65 +788,61 @@ - template - S_ComponentGridFunction :: - S_ComponentGridFunction (const S_GridFunction & agf_parent, int acomp) - : S_GridFunction (dynamic_cast (*agf_parent.GetFESpace())[acomp], - agf_parent.GetName()+"."+ToString (acomp+1), Flags()), + ComponentGridFunction :: + ComponentGridFunction (shared_ptr agf_parent, int acomp) + : GridFunction (dynamic_cast (*agf_parent->GetFESpace())[acomp], + agf_parent->GetName()+"."+ToString (acomp+1), Flags()), gf_parent(agf_parent), comp(acomp) { - this->SetVisual(agf_parent.GetVisual()); - const CompoundFESpace * cfe = dynamic_cast(this->GetFESpace().get()); - if (cfe) - { - int nsp = cfe->GetNSpaces(); - this->compgfs.SetSize(nsp); - for (int i = 0; i < nsp; i++) - this->compgfs[i] = make_shared> (*this, i); - } - - // this->Visualize (this->name); + this->SetVisual(agf_parent->GetVisual()); if (this->visual) Visualize (this, this->name); } - template - S_ComponentGridFunction :: - ~S_ComponentGridFunction () + ComponentGridFunction :: + ~ComponentGridFunction () { this -> vec = NULL; // base-class destructor must not delete the vector } - template - void S_ComponentGridFunction :: Update() + void ComponentGridFunction :: Update() { - const CompoundFESpace & cfes = dynamic_cast (*gf_parent.GetFESpace().get()); + if(!gf_parent->IsUpdated()) + gf_parent->Update(); + const CompoundFESpace & cfes = dynamic_cast (*gf_parent->GetFESpace().get()); - this -> vec.SetSize (gf_parent.GetMultiDim()); - GridFunction::multidim = gf_parent.GetMultiDim(); + this -> vec.SetSize (gf_parent->GetMultiDim()); + GridFunction::multidim = gf_parent->GetMultiDim(); #ifdef PARALLEL if (MyMPI_GetNTasks()>1) { auto pds = cfes[comp]->GetParallelDofs(); - for (int i = 0; i < gf_parent.GetMultiDim(); i++) + for (int i = 0; i < gf_parent->GetMultiDim(); i++) { - auto fvec = gf_parent.GetVector(i).Range (cfes.GetRange(comp)); - (this->vec)[i] = make_shared> (fvec.Size(), (SCAL*)fvec.Memory(), pds, CUMULATED); + auto fvec = gf_parent->GetVector(i).Range (cfes.GetRange(comp)); + if(IsComplex()) + (this->vec)[i] = make_shared> (fvec.Size(), (Complex*)fvec.Memory(), pds, CUMULATED); + else + (this->vec)[i] = make_shared> (fvec.Size(), (double*)fvec.Memory(), pds, CUMULATED); } } else #endif { - for (int i = 0; i < gf_parent.GetMultiDim(); i++) - (this->vec)[i] = gf_parent.GetVector(i).Range (cfes.GetRange(comp)); + for (int i = 0; i < gf_parent->GetMultiDim(); i++) + (this->vec)[i] = gf_parent->GetVector(i).Range (cfes.GetRange(comp)); } this -> level_updated = this -> ma->GetNLevels(); - - for (int i = 0; i < this->compgfs.Size(); i++) - this->compgfs[i]->Update(); + compgfs.remove_if([](auto& wptr) + { + if(wptr.expired()) + return true; + wptr.lock()->Update(); + return false; + }); } @@ -878,20 +882,6 @@ vec.SetSize (this->multidim); vec = 0; - const CompoundFESpace * cfe = dynamic_cast(this->GetFESpace().get()); - if (cfe) - { - int nsp = cfe->GetNSpaces(); - compgfs.SetSize(nsp); - for (int i = 0; i < nsp; i++) - compgfs[i] = make_shared> (*this, i); - } - - // this->Visualize (this->name); - /* - if (this->visual) - Visualize(shared_ptr (this, NOOP_Deleter), this->name); - */ if (this->visual) Visualize(this, this->name); } @@ -957,10 +947,13 @@ this -> level_updated = this -> ma->GetNLevels(); - // const CompoundFESpace * cfe = dynamic_cast(&GridFunction :: GetFESpace()); - // if (cfe) - for (int i = 0; i < compgfs.Size(); i++) - compgfs[i]->Update(); + this->compgfs.remove_if([](auto& wptr) + { + if(wptr.expired()) + return true; + wptr.lock()->Update(); + return false; + }); } catch (Exception & e) { @@ -1583,7 +1576,7 @@ bool aapplyd) : SolutionData (agf->GetName(), -1, agf->GetFESpace()->IsComplex()), - ma(ama), gf(dynamic_pointer_cast> (agf)), + ma(ama), gf(agf), applyd(aapplyd) // , lh(10000013, "VisualizedGridFunction 2") { if(abfi2d) @@ -1606,7 +1599,7 @@ bool aapplyd) : SolutionData (agf->GetName(), -1, agf->GetFESpace()->IsComplex()), - ma(ama), gf(dynamic_pointer_cast> (agf)), + ma(ama), gf(agf), applyd(aapplyd) // , lh(10000002, "VisualizeGridFunction") { for(int i=0; i> compgfs; /// the actual data, array for multi-dim Array> vec; /// component GridFunctions if fespace is a CompoundFESpace - Array> compgfs; shared_ptr derivcf; public: /// @@ -185,8 +186,14 @@ virtual bool IsUpdated () const; - int GetNComponents () const { return compgfs.Size(); } - shared_ptr GetComponent (int compound_comp) const; + int GetNComponents () const + { + auto compfes = dynamic_pointer_cast(fespace); + if(compfes) + return compfes->GetNSpaces(); + return 0; + } + shared_ptr GetComponent (int compound_comp); shared_ptr GetDeriv() { @@ -295,7 +302,6 @@ class NGS_DLL_HEADER T_GridFunction : public S_GridFunction::TSCAL> { using S_GridFunction::TSCAL>::vec; - using S_GridFunction::TSCAL>::compgfs; public: typedef typename mat_traits::TSCAL TSCAL; @@ -332,15 +338,16 @@ - template - class NGS_DLL_HEADER S_ComponentGridFunction : public S_GridFunction + class NGS_DLL_HEADER ComponentGridFunction : public GridFunction { - const S_GridFunction & gf_parent; + shared_ptr gf_parent; int comp; public: - S_ComponentGridFunction (const S_GridFunction & agf_parent, int acomp); - virtual ~S_ComponentGridFunction (); - virtual void Update (); + ComponentGridFunction (shared_ptr agf_parent, int acomp); + ~ComponentGridFunction () override; + void Update () override; + void Load(istream& ist) override { throw Exception("Load not implemented for ComponentGF"); } + void Save(ostream& ost) const override { throw Exception("Save not implemented for ComponentGF"); } }; @@ -352,7 +359,7 @@ class NGS_DLL_HEADER VisualizeGridFunction : public netgen::SolutionData { shared_ptr ma; - shared_ptr> gf; + shared_ptr gf; Array> bfi2d; Array> bfi3d; bool applyd; diff -Nru ngsolve-6.2.1810/comp/hcurlcurlfespace.cpp ngsolve-6.2.1901/comp/hcurlcurlfespace.cpp --- ngsolve-6.2.1810/comp/hcurlcurlfespace.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/hcurlcurlfespace.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -673,7 +673,7 @@ /// Christoffel Symbol of second kind for HCurlCurl - /* + template > class DiffOpChristoffel2HCurlCurl : public DiffOp > { @@ -709,27 +709,21 @@ const TVX & x, TVY & y, LocalHeap & lh) { - throw Exception("Christoffel symbol of second art apply is not working yet!"); - + HeapReset hr(lh); const HCurlCurlFiniteElement & bfel = dynamic_cast&> (fel); - HeapReset hr(lh); typedef typename TVX::TSCAL TSCAL; int nd_u = bfel.GetNDof(); FlatMatrixFixWidth bmat(nd_u, lh); - bfel.CalcShape (mip.IP(), bmat); + bfel.CalcMappedShape_Matrix (mip, bmat); - Vec hv = Trans (bmat) * x; - SliceMatrix matshape(D,D,1,&hv[0]); - auto jac = mip.GetJacobian(); - auto d2 = sqr(mip.GetJacobiDet()); - Mat defmat = 1/d2*jac*matshape*Trans(jac); + Vec hv = Trans(bmat) * x; + Mat defmat = hv; Mat invmat = Inv(defmat); - FlatMatrix mat(nd_u,D*D*D, lh); DiffOpChristoffelHCurlCurl::GenerateMatrix(fel, mip, Trans(mat), lh); - Vec hdv = Trans(mat)*x; + Vec hdv = Trans(mat) * x; for (int i=0; i> x, BareSliceVector y) //{ //} - };*/ + }; HCurlCurlFESpace :: HCurlCurlFESpace (shared_ptr ama,const Flags & flags,bool checkflags) @@ -1197,12 +1191,12 @@ case 2: additional.Set ("grad", make_shared>> ()); additional.Set ("christoffel", make_shared>> ()); - //additional.Set ("christoffel2", make_shared>> ()); + additional.Set ("christoffel2", make_shared>> ()); break; case 3: additional.Set ("grad", make_shared>> ()); additional.Set ("christoffel", make_shared>> ()); - //additional.Set ("christoffel2", make_shared>> ()); + additional.Set ("christoffel2", make_shared>> ()); break; default: ; diff -Nru ngsolve-6.2.1810/comp/hdivdivfespace.cpp ngsolve-6.2.1901/comp/hdivdivfespace.cpp --- ngsolve-6.2.1810/comp/hdivdivfespace.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/hdivdivfespace.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -521,124 +521,132 @@ int incrorder_xx2_bd = HDivDivFE::incrorder_xx2_bd; int incrorder_zz1_bd = HDivDivFE::incrorder_zz1_bd; // int incrorder_zz2_bd = HDivDivFE::incrorder_zz2_bd; - first_facet_dof.SetSize (ma->GetNFacets()+1); - first_element_dof.SetSize (ma->GetNE()+1); - order_facet.SetSize(ma->GetNFacets()); - order_facet = INT<2>(uniform_order_facet,uniform_order_facet); + bool first_update = GetTimeStamp() < ma->GetTimeStamp(); + if (first_update) timestamp = NGS_Object::GetNextTimeStamp(); - order_inner.SetSize(ma->GetNE()); - order_inner = INT<3>(uniform_order_inner,uniform_order_inner,uniform_order_inner); + if (first_update) + { + first_facet_dof.SetSize (ma->GetNFacets()+1); + first_element_dof.SetSize (ma->GetNE()+1); - Array fine_facet(ma->GetNFacets()); - fine_facet = false; - for(auto el : ma->Elements(VOL)) - fine_facet[el.Facets()] = true; + order_facet.SetSize(ma->GetNFacets()); + order_facet = INT<2>(uniform_order_facet,uniform_order_facet); - ndof = 0; - for(auto i : Range(ma->GetNFacets())) - { - first_facet_dof[i] = ndof; - if(!fine_facet[i]) continue; + order_inner.SetSize(ma->GetNE()); + order_inner = INT<3>(uniform_order_inner,uniform_order_inner,uniform_order_inner); - INT<2> of = order_facet[i]; - switch(ma->GetFacetType(i)) - { - case ET_SEGM: - ndof += of[0] + 1; break; - case ET_TRIG: - ndof += (of[0] + 1+incrorder_zz1_bd)*(of[0] + 2+incrorder_zz1_bd) / 2; break; - case ET_QUAD: - ndof += (of[0] + 1+incrorder_xx1_bd)*(of[1] + 1+incrorder_xx2_bd); break; - default: - throw Exception("illegal facet type"); - } - } - first_facet_dof.Last() = ndof; - if(discontinuous) ndof = 0; + fine_facet.SetSize(ma->GetNFacets()); + fine_facet = false; + for(auto el : ma->Elements(VOL)) + fine_facet[el.Facets()] = true; - for(auto i : Range(ma->GetNE())) - { - ElementId ei(VOL, i); - first_element_dof[i] = ndof; - INT<3> oi = order_inner[i]; - switch(ma->GetElType(ei)) - { - case ET_TRIG: - ndof += 3*(oi[0]+1)*(oi[0]+2)/2 - 3*(oi[0]+1); - if(plus) ndof += 2*oi[0]; - if(discontinuous) - { - /* - auto fnums = ma->GetElFacets(ei); - for(int ii=0; iiGetNFacets())) { - ndof += first_facet_dof[fnums[ii]+1] - first_facet_dof[fnums[ii]]; + first_facet_dof[i] = ndof; + if(!fine_facet[i]) continue; + + INT<2> of = order_facet[i]; + switch(ma->GetFacetType(i)) + { + case ET_SEGM: + ndof += of[0] + 1; break; + case ET_TRIG: + ndof += (of[0] + 1+incrorder_zz1_bd)*(of[0] + 2+incrorder_zz1_bd) / 2; break; + case ET_QUAD: + ndof += (of[0] + 1+incrorder_xx1_bd)*(of[1] + 1+incrorder_xx2_bd); break; + default: + throw Exception("illegal facet type"); + } } - */ - for (auto f : ma->GetElFacets(ei)) - ndof += first_facet_dof[f+1] - first_facet_dof[f]; - } - break; - case ET_QUAD: - // original: - ndof += (oi[0]+1+HDivDivFE::incsg)*(oi [0]+1+HDivDivFE::incsg) - + (oi[0]+2)*(oi[0])*2 - + 2*(oi[0]+1+HDivDivFE::incsugv) +1; + first_facet_dof.Last() = ndof; + if(discontinuous) ndof = 0; + + for(auto i : Range(ma->GetNE())) + { + ElementId ei(VOL, i); + first_element_dof[i] = ndof; + INT<3> oi = order_inner[i]; + switch(ma->GetElType(ei)) + { + case ET_TRIG: + ndof += 3*(oi[0]+1)*(oi[0]+2)/2 - 3*(oi[0]+1); + if(plus) ndof += 2*oi[0]; + if(discontinuous) + { + /* + auto fnums = ma->GetElFacets(ei); + for(int ii=0; iiGetElFacets(ei)) + ndof += first_facet_dof[f+1] - first_facet_dof[f]; + } + break; + case ET_QUAD: + // original: + ndof += (oi[0]+1+HDivDivFE::incsg)*(oi [0]+1+HDivDivFE::incsg) + + (oi[0]+2)*(oi[0])*2 + + 2*(oi[0]+1+HDivDivFE::incsugv) +1; - //ndof += 2*(oi[0]+2)*(oi[0]+1) +1; - /* - ndof += (oi[0]+1+HDivDivFE::incsg)*(oi [0]+1+HDivDivFE::incsg) - + (oi[0]+1)*(oi[0])*2 - + 2*(oi[0]+1+HDivDivFE::incsugv) +2; - if (plus) ndof += 2*oi[0]; - */ - if(discontinuous) - { - for (auto f : ma->GetElFacets(ei)) - ndof += first_facet_dof[f+1] - first_facet_dof[f]; - } - break; - case ET_PRISM: - ndof += 3*(oi[0]+1+incrorder_xx1)*(oi[0]+incrorder_xx1)*(oi[2]+1+incrorder_xx2)/2 + - (oi[0]+1+incrorder_zz1)*(oi[0]+2+incrorder_zz1)*(oi[2]-1+incrorder_zz2)/2 + - (oi[0]+1)*(oi[0]+2)*(oi[2]+1)/2*2; - if(discontinuous) - { - for (auto f : ma->GetElFacets(ei)) - ndof += first_facet_dof[f+1] - first_facet_dof[f]; - } - break; - case ET_HEX: - ndof += 3*(oi[0]+2)*(oi[0])*(oi[0]+2) + 3*(oi[0]+1)*(oi[0]+2)*(oi[0]+1); - if(discontinuous) - { - for (auto f : ma->GetElFacets(ei)) - ndof += first_facet_dof[f+1] - first_facet_dof[f]; - } - break; - case ET_TET: - ndof += (oi[0]+1)*(oi[0]+2)*(oi[0]+1); + //ndof += 2*(oi[0]+2)*(oi[0]+1) +1; + /* + ndof += (oi[0]+1+HDivDivFE::incsg)*(oi [0]+1+HDivDivFE::incsg) + + (oi[0]+1)*(oi[0])*2 + + 2*(oi[0]+1+HDivDivFE::incsugv) +2; + if (plus) ndof += 2*oi[0]; + */ + if(discontinuous) + { + for (auto f : ma->GetElFacets(ei)) + ndof += first_facet_dof[f+1] - first_facet_dof[f]; + } + break; + case ET_PRISM: + ndof += 3*(oi[0]+1+incrorder_xx1)*(oi[0]+incrorder_xx1)*(oi[2]+1+incrorder_xx2)/2 + + (oi[0]+1+incrorder_zz1)*(oi[0]+2+incrorder_zz1)*(oi[2]-1+incrorder_zz2)/2 + + (oi[0]+1)*(oi[0]+2)*(oi[2]+1)/2*2; + if(discontinuous) + { + for (auto f : ma->GetElFacets(ei)) + ndof += first_facet_dof[f+1] - first_facet_dof[f]; + } + break; + case ET_HEX: + ndof += 3*(oi[0]+2)*(oi[0])*(oi[0]+2) + 3*(oi[0]+1)*(oi[0]+2)*(oi[0]+1); + if(discontinuous) + { + for (auto f : ma->GetElFacets(ei)) + ndof += first_facet_dof[f+1] - first_facet_dof[f]; + } + break; + case ET_TET: + ndof += (oi[0]+1)*(oi[0]+2)*(oi[0]+1); + if(discontinuous) + { + for (auto f : ma->GetElFacets(ei)) + ndof += first_facet_dof[f+1] - first_facet_dof[f]; + } + break; + default: + throw Exception(string("illegal element type") + ToString(ma->GetElType(ei))); + } + } + first_element_dof.Last() = ndof; if(discontinuous) - { - for (auto f : ma->GetElFacets(ei)) - ndof += first_facet_dof[f+1] - first_facet_dof[f]; - } - break; - default: - throw Exception(string("illegal element type") + ToString(ma->GetElType(ei))); + first_facet_dof = 0; + + if (print) + { + *testout << "Hdivdiv firstfacetdof = " << first_facet_dof << endl; + *testout << "Hdivdiv firsteldof = " << first_element_dof << endl; + } } - } - first_element_dof.Last() = ndof; - if(discontinuous) - first_facet_dof = 0; UpdateCouplingDofArray(); - if (print) - { - *testout << "Hdivdiv firstfacetdof = " << first_facet_dof << endl; - *testout << "Hdivdiv firsteldof = " << first_element_dof << endl; - } } void HDivDivFESpace :: UpdateCouplingDofArray () @@ -665,6 +673,64 @@ } + void HDivDivFESpace :: SetOrder (NodeId ni, int order) + { + if (order_policy == CONSTANT_ORDER || order_policy == NODE_TYPE_ORDER) + throw Exception("In HDivDivFESpace::SetOrder. Order policy is constant or node-type!"); + else if (order_policy == OLDSTYLE_ORDER) + order_policy = VARIABLE_ORDER; + + if (order < 0) + order = 0; + + switch( CoDimension(ni.GetType(), ma->GetDimension()) ) + { + case 1: + if (ni.GetNr() < order_facet.Size()) + order_facet[ni.GetNr()] = fine_facet[ni.GetNr()] ? order : 0; + break; + case 0: + if (ma->GetDimension() == 2 && ni.GetType() == NT_FACE) + { + Array elnr; + ma->GetFacetSurfaceElements(ni.GetNr(),elnr); + if (elnr[0] < order_inner.Size()) + order_inner[elnr[0]] = order; + } + else if (ni.GetNr() < order_inner.Size()) + order_inner[ni.GetNr()] = order; + break; + default: + break; + } + } + + int HDivDivFESpace :: GetOrder (NodeId ni) const + { + switch( CoDimension(ni.GetType(), ma->GetDimension()) ) + { + case 1: + if (ni.GetNr() < order_facet.Size()) + return order_facet[ni.GetNr()][0]; + break; + case 0: + if (ma->GetDimension() == 2 && ni.GetType() == NT_FACE) + { + Array elnr; + ma->GetFacetSurfaceElements(ni.GetNr(),elnr); + if (elnr[0] < order_inner.Size()) + return order_inner[elnr[0]][0]; + } + else if (ni.GetNr() < order_inner.Size()) + return order_inner[ni.GetNr()][0]; + break; + default: + break; + } + + return 0; + } + FiniteElement & HDivDivFESpace :: GetFE (ElementId ei,Allocator & alloc) const { diff -Nru ngsolve-6.2.1810/comp/hdivdivfespace.hpp ngsolve-6.2.1901/comp/hdivdivfespace.hpp --- ngsolve-6.2.1810/comp/hdivdivfespace.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/hdivdivfespace.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -23,6 +23,8 @@ int uniform_order_facet; int uniform_order_inner; + Array fine_facet; + public: HDivDivFESpace (shared_ptr ama, const Flags & flags, bool checkflags=false); static DocInfo GetDocu (); @@ -37,7 +39,9 @@ virtual size_t GetNDof () const throw() override { return ndof; } virtual FiniteElement & GetFE (ElementId ei, Allocator & alloc) const override; - + + virtual void SetOrder (NodeId ni, int order) override; + virtual int GetOrder (NodeId ni) const override; virtual void GetVertexDofNrs (int vnr, Array & dnums) const override { diff -Nru ngsolve-6.2.1810/comp/hdivdivsurfacespace.cpp ngsolve-6.2.1901/comp/hdivdivsurfacespace.cpp --- ngsolve-6.2.1810/comp/hdivdivsurfacespace.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/hdivdivsurfacespace.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -305,11 +305,12 @@ first_face_dof[nfa] = ndof; first_element_dof.SetSize(nel + 1); - for (size_t i = 0; i < nel; i++) + for(auto i : Range(ma->GetNSE())) { + ElementId ei(BND, i); first_element_dof[i] = ndof; - switch (ma->GetElType({BND,i})) + switch (ma->GetElType(ei)) { case ET_TRIG: ndof += 3 * order*(order + 1) / 2; @@ -336,21 +337,16 @@ if (noncontinuous) { - //cout << "Update before discont" << endl; ndof = 0; - Array pnums; - - for (size_t i = 0; i < nel; i++) + + for(auto i : Range(ma->GetNSE())) { - ElementId ei = { BND, i }; + ElementId ei(BND, i); first_element_dof[i] = ndof; - auto facets = ma->GetElEdges(ei); // add facet dofs - for (int fa = 0; fa < facets.Size(); fa++) - { - ndof += first_face_dof[facets[fa] + 1] - first_face_dof[facets[fa]]; - } + for (auto facets : ma->GetElEdges(ei)) + ndof += first_face_dof[facets + 1] - first_face_dof[facets]; // add inner dofs switch (ma->GetElType(ei)) @@ -359,7 +355,7 @@ ndof += 3 * order*(order + 1) / 2; break; case ET_QUAD: - ndof += 3 * (order + 1) * (order + 1) - 2 - 2*order; + ndof += 3 * (order + 1) * (order + 1) - 2; break; default: break; diff -Nru ngsolve-6.2.1810/comp/l2hofespace.cpp ngsolve-6.2.1901/comp/l2hofespace.cpp --- ngsolve-6.2.1810/comp/l2hofespace.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/l2hofespace.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -705,7 +705,8 @@ LocalHeap & lh) const { static Timer t("SolveM"); RegionTimer reg(t); - + if (rho && rho->Dimension() != 1) + throw Exception("L2HighOrderFESpace::SolveM needs a scalar density"); IterateElements (*this, VOL, lh, [&rho, &vec,this] (FESpace::Element el, LocalHeap & lh) { @@ -1422,7 +1423,7 @@ for (auto i_ip : Range(mir)) { auto col = mat.Col(i_ip); - auto & mip = static_cast>&>(mir[i_ip]); + auto & mip = static_cast>&>(mir[i_ip]); auto trafo = mip.GetJacobianInverse(); for (int k = 0; k < DIM_SPACE; k++) @@ -1439,11 +1440,11 @@ static void ApplySIMDIR (const FiniteElement & bfel, const SIMD_BaseMappedIntegrationRule & bmir, BareSliceVector x, BareSliceMatrix> y) { - auto & mir = static_cast&> (bmir); + auto & mir = static_cast&> (bmir); auto & fel = static_cast (bfel); auto & feli = static_cast (fel[0]); size_t ndofi = feli.GetNDof(); - + STACK_ARRAY(double, memx, DIM_SPACE*ndofi); FlatMatrix matx(ndofi, DIM_SPACE, &memx[0]); for (size_t k = 0; k < DIM_SPACE; k++) @@ -1464,7 +1465,7 @@ static void AddTransSIMDIR (const FiniteElement & bfel, const SIMD_BaseMappedIntegrationRule & bmir, BareSliceMatrix> y, BareSliceVector x) { - auto & mir = static_cast&> (bmir); + auto & mir = static_cast&> (bmir); auto & fel = static_cast (bfel); auto & feli = static_cast (fel[0]); size_t ndofi = feli.GetNDof(); @@ -1622,13 +1623,17 @@ user-level. Additionally, some operators are added for convenience and performance: One can evaluate the vector-valued function, and one can take the gradient. )raw_string"; - docu.Arg("Piola") = "bool = False\n" + docu.Arg("piola") = "bool = False\n" " Use Piola transform to map to physical element\n" " allows to use the div-differential operator."; docu.Arg("covariant") = "bool = False\n" " Use the covariant transform to map to physical element\n" " allows to use the curl-differential operator."; - + docu.Arg("all_dofs_together") = "bool = True\n" + " dofs within one scalar component are together."; + docu.Arg("hide_all_dofs") = "bool = False\n" + " all dofs are condensed without a global dofnr"; + return docu; } @@ -1638,7 +1643,8 @@ { type = "VectorL2"; Flags compflags = flags; - compflags.SetFlag("all_dofs_together"); + if (!flags.GetDefineFlagX("all_dofs_together").IsFalse()) + compflags.SetFlag("all_dofs_together"); for (int i = 0; i < ma->GetDimension(); i++) AddSpace (make_shared (ama, compflags)); @@ -1716,6 +1722,7 @@ void VectorL2FESpace :: SolveM (CoefficientFunction * rho, BaseVector & vec, LocalHeap & lh) const { + /* if (piola) { switch (ma->GetDimension()) @@ -1739,6 +1746,19 @@ } return; } + */ + + if (covariant || piola || (rho && rho->Dimension() > 1) ) + { + switch (ma->GetDimension()) + { + case 1: SolveM_Dim<1>(rho, vec, lh); break; + case 2: SolveM_Dim<2>(rho, vec, lh); break; + case 3: SolveM_Dim<3>(rho, vec, lh); break; + default: throw Exception("VectorL2FESpace::SolveM: illegal dimension"); + } + return; + } for (size_t i = 0; i < spaces.Size(); i++) { @@ -1748,7 +1768,7 @@ } - + void VectorL2FESpace :: ApplyM (CoefficientFunction * rho, BaseVector & vec, LocalHeap & lh) const @@ -1783,12 +1803,102 @@ spaces[i] -> ApplyM (rho, veci, lh); } } - - + + + template + void VectorL2FESpace :: + SolveM_Dim (CoefficientFunction * rho, BaseVector & vec, + LocalHeap & lh) const + { + static Timer t("SolveM - Vec"); RegionTimer reg(t); + + IterateElements + (*this, VOL, lh, + [&rho, &vec,this] (FESpace::Element el, LocalHeap & lh) + { + auto & fel = static_cast(el.GetFE()); + auto & feli = static_cast(fel[0]); + const ElementTransformation & trafo = el.GetTrafo(); + + Array dnums(fel.GetNDof(), lh); + GetDofNrs (el.Nr(), dnums); + + FlatVector elx(feli.GetNDof()*DIM, lh); + vec.GetIndirect(dnums, elx); + auto melx = elx.AsMatrix(DIM, feli.GetNDof()); + + FlatVector diag_mass(feli.GetNDof(), lh); + feli.GetDiagMassMatrix (diag_mass); + + bool curved = trafo.IsCurvedElement(); + if (rho && !rho->ElementwiseConstant()) curved = true; + curved = false; // curved not implemented + + if (!curved) + { + IntegrationRule ir(fel.ElementType(), 0); + MappedIntegrationRule mir(ir, trafo, lh); + Mat rhoi; + if (!rho) + rhoi = Identity(DIM); + else if (rho->Dimension() == 1) + rhoi = rho->Evaluate(mir[0]) * Identity(DIM); + else + rho -> Evaluate(mir[0], FlatVector<> (DIM*DIM, &rhoi(0,0))); + + Mat trans; + if (piola) + trans = (1/mir[0].GetMeasure()) * Trans(mir[0].GetJacobian()) * rhoi * mir[0].GetJacobian(); + else if (covariant) + trans = mir[0].GetMeasure() * mir[0].GetJacobianInverse() * rhoi * Trans(mir[0].GetJacobianInverse()); + else + trans = mir[0].GetMeasure() * rhoi; + Mat invtrans = Inv(trans); + + for (int i = 0; i < melx.Width(); i++) + { + Vec hv = melx.Col(i); + hv /= diag_mass(i); + melx.Col(i) = invtrans * hv; + } + } + /* + else + { + SIMD_IntegrationRule ir(fel.ElementType(), 2*fel.Order()); + auto & mir = trafo(ir, lh); + FlatVector> pntvals(ir.Size(), lh); + FlatMatrix> rhovals(1, ir.Size(), lh); + if (rho) rho->Evaluate (mir, rhovals); + + for (int i = 0; i < melx.Height(); i++) + melx.Row(i) /= diag_mass(i); + for (int comp = 0; comp < dimension; comp++) + { + fel.Evaluate (ir, melx.Col(comp), pntvals); + if (rho) + for (size_t i = 0; i < ir.Size(); i++) + pntvals(i) *= ir[i].Weight() / (mir[i].GetMeasure() * rhovals(0,i)); + else + for (size_t i = 0; i < ir.Size(); i++) + pntvals(i) *= ir[i].Weight() / mir[i].GetMeasure(); + + melx.Col(comp) = 0.0; + fel.AddTrans (ir, pntvals, melx.Col(comp)); + } + for (int i = 0; i < melx.Height(); i++) + melx.Row(i) /= diag_mass(i); + } + */ + vec.SetIndirect(dnums, elx); + }); + } + +#ifdef OLD template void VectorL2FESpace :: SolveMPiola (CoefficientFunction * rho, BaseVector & vec, @@ -1904,9 +2014,9 @@ Mat rhoi; if (!rho) - rhoi = Identity(3); + rhoi = Identity(DIM); else if (rho->Dimension() == 1) - rhoi = rho->Evaluate(mir[0]) * Identity(3); + rhoi = rho->Evaluate(mir[0]) * Identity(DIM); else rho -> Evaluate(mir[0], FlatVector<> (DIM*DIM, &rhoi(0,0))); @@ -1956,7 +2066,8 @@ vec.SetIndirect(dnums, elx); }); } - +#endif + @@ -2004,9 +2115,9 @@ Mat rhoi; if (!rho) - rhoi = Identity(3); + rhoi = Identity(DIM); else if (rho->Dimension() == 1) - rhoi = rho->Evaluate(mir[0]) * Identity(3); + rhoi = rho->Evaluate(mir[0]) * Identity(DIM); else rho -> Evaluate(mir[0], FlatVector<> (DIM*DIM, &rhoi(0,0))); diff -Nru ngsolve-6.2.1810/comp/l2hofespace.hpp ngsolve-6.2.1901/comp/l2hofespace.hpp --- ngsolve-6.2.1810/comp/l2hofespace.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/l2hofespace.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -212,12 +212,18 @@ LocalHeap & lh) const override; template + void SolveM_Dim (CoefficientFunction * rho, BaseVector & vec, + LocalHeap & lh) const; + + /* + template void SolveMPiola (CoefficientFunction * rho, BaseVector & vec, LocalHeap & lh) const; template void SolveMCovariant (CoefficientFunction * rho, BaseVector & vec, LocalHeap & lh) const; - + */ + template void ApplyMPiola (CoefficientFunction * rho, BaseVector & vec, diff -Nru ngsolve-6.2.1810/comp/numberfespace.cpp ngsolve-6.2.1901/comp/numberfespace.cpp --- ngsolve-6.2.1810/comp/numberfespace.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/numberfespace.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -32,6 +32,13 @@ mat(0,0) = 1; } + static void GenerateMatrixSIMDIR (const FiniteElement & bfel, + const SIMD_BaseMappedIntegrationRule & mir, + BareSliceMatrix> mat) + { + mat.Row(0).AddSize(mir.Size()) = SIMD(1); + } + using DiffOp::ApplySIMDIR; /* template diff -Nru ngsolve-6.2.1810/comp/postproc.cpp ngsolve-6.2.1901/comp/postproc.cpp --- ngsolve-6.2.1810/comp/postproc.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/postproc.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -380,7 +380,7 @@ template void SetValues (shared_ptr coef, - GridFunction & bu, + GridFunction & u, VorB vb, const Region * reg, DifferentialOperator * diffop, @@ -388,8 +388,6 @@ { static Timer sv("timer setvalues"); RegionTimer r(sv); - S_GridFunction & u = dynamic_cast &> (bu); - auto fes = u.GetFESpace(); shared_ptr ma = fes->GetMeshAccess(); int dim = fes->GetDimension(); diff -Nru ngsolve-6.2.1810/comp/python_comp.cpp ngsolve-6.2.1901/comp/python_comp.cpp --- ngsolve-6.2.1810/comp/python_comp.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/python_comp.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -475,12 +475,12 @@ return self->DerivEvaluator()->Name(); }, "name of the canonical derivative") .def("Operator", - [] (const spProxy self, string name) -> py::object + [] (const spProxy self, string name) { auto op = self->GetAdditionalProxy(name); - if (op) - return py::cast(op); - return py::none(); + if (!op) + throw Exception(string("Operator \"") + name + string("\" does not exist for ") + self->GetFESpace()->GetClassName() + string("!")); + return op; }, py::arg("name"), "Use an additional operator of the finite element space") .def("Operators", [] (const spProxy self) @@ -1110,9 +1110,16 @@ }, docu_string("Return a tuple of trial and testfunction")) + .def("InvM", + [] (const shared_ptr self, + shared_ptr rho) -> shared_ptr + { + return make_shared (self, rho, glh); + }, py::arg("rho") = nullptr) + .def("SolveM", [] (const shared_ptr self, - BaseVector& vec, spCF rho) + BaseVector& vec, spCF rho) { self->SolveM(rho.get(), vec, glh); }, py::arg("vec"), py::arg("rho")=nullptr, docu_string(R"raw_string( Solve with the mass-matrix. Available only for L2-like spaces. @@ -1534,7 +1541,7 @@ reg = &py::extract(definedon)(); py::gil_scoped_release release; - + if(tpspace) { Transfer2TPMesh(cf.get(),self.get(),glh); @@ -1606,31 +1613,29 @@ "returns list of available differential operators") .def("Operator", - [](shared_ptr self, string name, VorB vb) -> py::object // shared_ptr + [](shared_ptr self, string name, VorB vb) { - if (self->GetFESpace()->GetAdditionalEvaluators().Used(name)) + if (!self->GetFESpace()->GetAdditionalEvaluators().Used(name)) + throw Exception(string("Operator \"") + name + string("\" does not exist for ") + self->GetFESpace()->GetClassName() + string("!")); + auto diffop = self->GetFESpace()->GetAdditionalEvaluators()[name]; + shared_ptr coef; + switch(vb) { - auto diffop = self->GetFESpace()->GetAdditionalEvaluators()[name]; - shared_ptr coef; - switch(vb) - { - case VOL: - coef = make_shared (self, diffop); - break; - case BND: - coef = make_shared (self, nullptr,diffop); - break; - case BBND: - coef = make_shared (self, nullptr,nullptr,diffop); - break; - case BBBND: - throw Exception ("there are no Operators with BBBND"); - } - coef->SetDimensions(diffop->Dimensions()); - coef->generated_from_operator = name; - return py::cast(shared_ptr(coef)); + case VOL: + coef = make_shared (self, diffop); + break; + case BND: + coef = make_shared (self, nullptr,diffop); + break; + case BBND: + coef = make_shared (self, nullptr,nullptr,diffop); + break; + case BBBND: + throw Exception ("there are no Operators with BBBND"); } - return py::none(); + coef->SetDimensions(diffop->Dimensions()); + coef->generated_from_operator = name; + return coef; }, py::arg("name"), py::arg("VOL_or_BND")=VOL, docu_string(R"raw_string( Get access to an operator depending on the FESpace. @@ -1895,9 +1900,11 @@ )raw_string")) - .def_property_readonly("mat", [](BF & self) + .def_property_readonly("mat", [](shared_ptr self) -> shared_ptr { - auto mat = self.GetMatrixPtr(); + if (self->NonAssemble()) + return make_shared (self, glh); + auto mat = self->GetMatrixPtr(); if (!mat) throw py::type_error("matrix not ready - assemble bilinearform first"); return mat; @@ -2416,6 +2423,7 @@ mask = BitArray(ma->GetNRegions(vb)); mask.Set(); } + int dim = cf->Dimension(); if((region_wise || element_wise) && dim != 1) throw Exception("region_wise and element_wise only implemented for 1 dimensional coefficientfunctions"); @@ -2643,7 +2651,7 @@ vb = VorB(defon_region()); if (element_boundary) element_vb = BND; - + shared_ptr lfi; if (!skeleton) lfi = make_shared (cf, vb, element_vb); @@ -2714,7 +2722,7 @@ input additional integration order definedonelements : object - input definedonelements + input BitArray that marks all elements or facets (for skeleton-integrators) that the integrator is applied on simd_evaluate : bool input simd_evaluate. True -> tries to use SIMD for faster evaluation @@ -2742,6 +2750,7 @@ if (element_boundary) element_vb = BND; // check for DG terms bool has_other = false; + cf->TraverseTree ([&has_other] (CoefficientFunction & cf) { if (dynamic_cast (&cf)) @@ -2847,6 +2856,7 @@ // check for DG terms bool has_other = false; + cf->TraverseTree ([&has_other] (CoefficientFunction & cf) { if (dynamic_cast (&cf)) @@ -2890,7 +2900,8 @@ vb = VorB(defon_region()); if (element_boundary) element_vb = BND; - + + auto bfi = make_shared (cf, vb, element_vb); bfi -> SetBonusIntegrationOrder(bonus_intorder); if (defon_region.check()) diff -Nru ngsolve-6.2.1810/comp/python_comp_mesh.cpp ngsolve-6.2.1901/comp/python_comp_mesh.cpp --- ngsolve-6.2.1810/comp/python_comp_mesh.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/comp/python_comp_mesh.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -153,6 +153,16 @@ .def_property_readonly("faces", [](MeshNode & node) -> py::tuple { auto & mesh = node.Mesh(); + if (node.GetType() == NT_VERTEX) + { + Array fnums; + for (auto el : mesh.GetVertexElements(node.GetNr())) + for (auto face : mesh.GetElement(ElementId(VOL,el)).Faces()) + if (!fnums.Contains(face)) + fnums.Append(face); + QuickSort (fnums); + return MakePyTuple(Substitute(fnums, Nr2Face)); + } if (node.GetType() == NT_CELL) return MakePyTuple(Substitute(mesh.GetElFacets(ElementId(VOL, node.GetNr())), Nr2Face)); @@ -262,6 +272,21 @@ } }, "tuple of global face, edge or vertex numbers") + .def_property_readonly("elementnode", [](Ngs_Element &el) + { + switch (ElementTopology::GetSpaceDim(el.GetType())) + { + case 1: + return Nr2Edge (el.Edges()[0]); + case 2: + return Nr2Face (el.Faces()[0]); + case 3: + return NodeId(NT_CELL, el.Nr()); + default: + throw Exception ("Illegal dimension in Ngs_Element.elementnode"); + } + }, + "inner node, i.e. cell, face or edge node for 3D/2D/1D") .def_property_readonly("type", [](Ngs_Element &self) { return self.GetType(); }, "geometric shape of element") diff -Nru ngsolve-6.2.1810/debian/changelog ngsolve-6.2.1901/debian/changelog --- ngsolve-6.2.1810/debian/changelog 2018-11-29 09:48:24.000000000 +0000 +++ ngsolve-6.2.1901/debian/changelog 2019-01-12 00:19:05.000000000 +0000 @@ -1,10 +1,10 @@ -ngsolve (6.2.1810-0~ubuntu16.04.1) xenial; urgency=low +ngsolve (6.2.1901-0~ubuntu16.04.1) xenial; urgency=low * Auto build. - -- Launchpad Package Builder Thu, 29 Nov 2018 09:48:24 +0000 + -- Launchpad Package Builder Sat, 12 Jan 2019 00:19:05 +0000 -ngsolve (6.2.1810-0) xenial; urgency=low +ngsolve (6.2.1901-0) xenial; urgency=low * Initial release (Closes: #nnnn) diff -Nru ngsolve-6.2.1810/debian/git-build-recipe.manifest ngsolve-6.2.1901/debian/git-build-recipe.manifest --- ngsolve-6.2.1810/debian/git-build-recipe.manifest 2018-11-29 09:48:24.000000000 +0000 +++ ngsolve-6.2.1901/debian/git-build-recipe.manifest 2019-01-12 00:19:04.000000000 +0000 @@ -1,5 +1,5 @@ # git-build-recipe format 0.4 deb-version {debversion} -lp:~mhochsteger/+git/ngsolve git-commit:5a872d3824638eaa58e0ab6e6660c0f8faf1a5ef -nest ppa lp:~mhochsteger/+git/ngsolve debian git-commit:b2d70af53208b2a4c3539ead2287475cdace320a -nest netgen lp:~mhochsteger/+git/netgen external_dependencies/netgen git-commit:7934a348726cfc3380aff0c23b829c035b1094c7 +lp:~mhochsteger/+git/ngsolve git-commit:a31a905cac14b0c14c535b8063e2fd16941c4335 +nest ppa lp:~mhochsteger/+git/ngsolve debian git-commit:86fc7232bf8d6458d61f5bbb809f2fd686589e47 +nest netgen lp:~mhochsteger/+git/netgen external_dependencies/netgen git-commit:ab92bff3a05e98546eced55032bb43da5357ce4b nest pybind lp:~mhochsteger/+git/pybind11 external_dependencies/netgen/external_dependencies/pybind11 git-commit:2a150736601bb3113877bb673fb934bb60d46ec5 diff -Nru ngsolve-6.2.1810/debian/version.txt ngsolve-6.2.1901/debian/version.txt --- ngsolve-6.2.1810/debian/version.txt 2018-11-29 09:47:58.000000000 +0000 +++ ngsolve-6.2.1901/debian/version.txt 2019-01-12 00:18:44.000000000 +0000 @@ -1 +1 @@ -v6.2.1810-0-g5a872d38 +v6.2.1901-0-ga31a905c diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/cmake/external_projects/catch.cmake ngsolve-6.2.1901/external_dependencies/netgen/cmake/external_projects/catch.cmake --- ngsolve-6.2.1810/external_dependencies/netgen/cmake/external_projects/catch.cmake 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/cmake/external_projects/catch.cmake 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,18 @@ +include (ExternalProject) +find_program(GIT_EXECUTABLE git) +ExternalProject_Add( + project_catch + PREFIX ${CMAKE_BINARY_DIR}/catch + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.0.1 + TIMEOUT 10 + UPDATE_COMMAND "" # ${GIT_EXECUTABLE} pull + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD ON + ) + +# Expose required variable (CATCH_INCLUDE_DIR) to parent scope +ExternalProject_Get_Property(project_catch source_dir) +set(CATCH_INCLUDE_DIR ${source_dir}/single_include CACHE INTERNAL "Path to include folder for Catch") diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/cmake/external_projects/tcltk.cmake ngsolve-6.2.1901/external_dependencies/netgen/cmake/external_projects/tcltk.cmake --- ngsolve-6.2.1810/external_dependencies/netgen/cmake/external_projects/tcltk.cmake 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/cmake/external_projects/tcltk.cmake 2019-01-12 00:19:01.000000000 +0000 @@ -27,85 +27,35 @@ set(TCL_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies/src/project_tcl) set(TK_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies/src/project_tk) - set(TCL_INCLUDE_PATH ${TCL_DIR}/generic;${TCL_DIR}/macosx) - set(TK_INCLUDE_PATH ${TK_DIR}/generic;${TK_DIR}/macosx;${TK_DIR}/xlib) - find_package(TCL 8.6 REQUIRED) - list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk) - + set(TCL_INCLUDE_PATH "${TCL_DIR}/generic;${TCL_DIR}/macosx") + set(TK_INCLUDE_PATH "${TK_DIR}/generic;${TK_DIR}/macosx;${TK_DIR}/xlib") + string(REPLACE ";" "$" TCL_INC "${TCL_INCLUDE_PATH}") + string(REPLACE ";" "$" TK_INC "${TK_INCLUDE_PATH}") + + ExternalProject_Add(project_tkdnd + URL "http://sourceforge.net/projects/tkdnd/files/TkDND/TkDND%202.8/tkdnd2.8-src.tar.gz" + URL_MD5 a6d47a996ea957416469b12965d4db91 + DEPENDS project_tcl project_tk + DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies + PATCH_COMMAND patch < ${CMAKE_CURRENT_LIST_DIR}/tkdnd_macosx.patch + UPDATE_COMMAND "" # Disable update + BUILD_IN_SOURCE 1 + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/Contents/MacOS + -DTCL_INCLUDE_PATH=${TCL_INC} + -DTK_INCLUDE_PATH=${TK_INC} + -DTK_LIBRARY=${TK_LIBRARY} + -DTCL_LIBRARY=${TCL_LIBRARY} + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + ) + +list(APPEND NETGEN_DEPENDENCIES project_tkdnd) else() find_package(TCL 8.5 REQUIRED) endif() -# set(HOME $ENV{HOME}) -# set(tcl_prefix ${CMAKE_INSTALL_PREFIX}/../../) -# ExternalProject_Add(project_tcl -# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tcl8.6.4-src.tar.gz" -# URL_MD5 d7cbb91f1ded1919370a30edd1534304 -# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies -# UPDATE_COMMAND "" # Disable update -# CONFIGURE_COMMAND ../project_tcl/macosx/configure --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin -# BUILD_COMMAND make -j4 binaries libraries -# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers -# LOG_DOWNLOAD 1 -# LOG_BUILD 1 -# LOG_CONFIGURE 1 -# LOG_INSTALL 1 -# ) -# -# ExternalProject_Add(project_tk -# DEPENDS project_tcl -# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tk8.6.4-src.tar.gz" -# URL_MD5 261754d7dc2a582f00e35547777e1fea -# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies -# UPDATE_COMMAND "" # Disable update -# CONFIGURE_COMMAND ../project_tk/macosx/configure --enable-aqua=yes --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin --with-tcl=${tcl_prefix}/Contents/Frameworks/Tcl.framework -# BUILD_COMMAND make -j4 binaries libraries -# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers -# LOG_DOWNLOAD 1 -# LOG_BUILD 1 -# LOG_CONFIGURE 1 -# LOG_INSTALL 1 -# ) -# -# ExternalProject_Add(project_tkdnd -# URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz" -# URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb -# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies -# BUILD_IN_SOURCE 1 -# CONFIGURE_COMMAND "" -# BUILD_COMMAND "" -# INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS -# LOG_DOWNLOAD 1 -# LOG_CONFIGURE 1 -# LOG_BUILD 1 -# LOG_INSTALL 1 -# ) -# -# list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd) -# list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks) -# set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers) -# set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework) -# set(TK_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework) -# set(TK_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework/Headers) -# - - - -ExternalProject_Add(project_tkdnd - URL "http://sourceforge.net/projects/tkdnd/files/TkDND/TkDND%202.8/tkdnd2.8-src.tar.gz" - URL_MD5 a6d47a996ea957416469b12965d4db91 - DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies - PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_LIST_DIR}/tkdnd_macosx.patch - UPDATE_COMMAND "" # Disable update - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX}/Contents/MacOS --libdir=${CMAKE_INSTALL_PREFIX}/Contents/MacOS - BUILD_COMMAND make - INSTALL_COMMAND make install - LOG_DOWNLOAD 1 - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 -) -list(APPEND NETGEN_DEPENDENCIES project_tkdnd) elseif(WIN32) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/cmake/external_projects/tkdnd_macosx.patch ngsolve-6.2.1901/external_dependencies/netgen/cmake/external_projects/tkdnd_macosx.patch --- ngsolve-6.2.1810/external_dependencies/netgen/cmake/external_projects/tkdnd_macosx.patch 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/cmake/external_projects/tkdnd_macosx.patch 2019-01-12 00:19:01.000000000 +0000 @@ -1,35 +1,55 @@ -diff -Naur orig/tkdnd2.8/configure changed/tkdnd2.8/configure ---- tkdnd2.8/configure 2015-05-13 19:24:32.000000000 +0200 -+++ tkdnd2.8/configure 2016-02-22 15:26:37.000000000 +0100 -@@ -6145,7 +6145,7 @@ - - - -- PKG_CFLAGS="$PKG_CFLAGS -DMAC_TK_COCOA -std=gnu99 -x objective-c -fobjc-gc" -+ PKG_CFLAGS="$PKG_CFLAGS -DMAC_TK_COCOA -std=gnu99 -x objective-c" - - - -diff -Naur orig/tkdnd2.8/configure.in changed/tkdnd2.8/configure.in ---- tkdnd2.8/configure.in 2015-05-13 19:24:32.000000000 +0200 -+++ tkdnd2.8/configure.in 2016-02-22 15:26:44.000000000 +0100 -@@ -126,7 +126,7 @@ - - if test "${TEA_WINDOWINGSYSTEM}" = "aqua"; then - TEA_ADD_SOURCES([macosx/macdnd.m]) -- TEA_ADD_CFLAGS([-DMAC_TK_COCOA -std=gnu99 -x objective-c -fobjc-gc]) -+ TEA_ADD_CFLAGS([-DMAC_TK_COCOA -std=gnu99 -x objective-c]) - TEA_ADD_LIBS([-framework Cocoa -framework Carbon]) - fi - -diff -Naur orig/tkdnd2.8/macosx/macdnd.m changed/tkdnd2.8/macosx/macdnd.m ---- tkdnd2.8/macosx/macdnd.m 2015-07-06 21:49:14.000000000 +0200 -+++ tkdnd2.8/macosx/macdnd.m 2016-02-22 15:27:04.000000000 +0100 -@@ -16,6 +16,7 @@ - #import - #import - #import -+#undef panic - #import - #import +--- CMakeLists.txt 19:24:32.000000000 +0200 ++++ CMakeLists.txt 2018-12-05 11:34:59.000000000 +0100 +@@ -43,17 +43,18 @@ + ELSE ( WIN32 ) + ## Unix and OS X... + IF ( APPLE ) +- SET ( CMAKE_OSX_ARCHITECTURES "x86_64;i386" ) ++ SET ( CMAKE_OSX_ARCHITECTURES "x86_64") ++ SET( TK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../project_tk/) ++ SET( TCL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../project_tcl/) + FIND_LIBRARY ( COCOA_LIBRARY Cocoa ) + INCLUDE_DIRECTORIES ( macosx ) +- INCLUDE_DIRECTORIES ( /Library/Frameworks/Tk.framework/Versions/8.6/PrivateHeaders ) +- INCLUDE_DIRECTORIES ( /System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk-private ) +- INCLUDE_DIRECTORIES ( /System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk-private ) ++ INCLUDE_DIRECTORIES ( ${TCL_DIR}/macosx ${TCL_DIR}/generic ) ++ INCLUDE_DIRECTORIES ( ${TK_DIR}/macosx ${TK_DIR}/generic ${TK_DIR}/xlib ) + ADD_DEFINITIONS ( -DMAC_TK_COCOA -DMAC_OSX_TK) + ADD_DEFINITIONS ( -DMAC_OSX_TK ) + ADD_DEFINITIONS ( -std=gnu99 ) + ADD_DEFINITIONS ( -x objective-c ) +- ADD_DEFINITIONS ( -fobjc-gc ) ++# ADD_DEFINITIONS ( -fobjc-gc ) + ADD_DEFINITIONS ( -fno-objc-arc ) + # ADD_DEFINITIONS ( -fobjc-arc ) + LINK_LIBRARIES ( ${COCOA_LIBRARY} ) +@@ -125,8 +126,8 @@ + ## Locate Tcl/Tk + ## =========================================================================== + MESSAGE ( STATUS "Searching for Tcl/Tk..." ) +-FIND_PACKAGE ( TCL REQUIRED ) +-FIND_PACKAGE ( TclStub REQUIRED ) ++#FIND_PACKAGE ( TCL REQUIRED ) ++#FIND_PACKAGE ( TclStub REQUIRED ) + + ## Tcl/Tk info (useful for debug purposes)... + # MESSAGE ( STATUS " TCL_TCLSH: " ${TCL_TCLSH} ) +@@ -139,13 +140,13 @@ + # MESSAGE ( STATUS " TK_LIBRARY: " ${TK_LIBRARY} ) + + ## Enable Tcl/Tk stubs globally... +-ADD_DEFINITIONS ( -DUSE_TCL_STUBS ) +-ADD_DEFINITIONS ( -DUSE_TK_STUBS ) ++#ADD_DEFINITIONS ( -DUSE_TCL_STUBS ) ++#ADD_DEFINITIONS ( -DUSE_TK_STUBS ) + ADD_DEFINITIONS ( -DTCL_THREADS ) + INCLUDE_DIRECTORIES ( ${TCL_INCLUDE_PATH} ) + INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH} ) +-LINK_LIBRARIES ( ${TCL_STUB_LIBRARY} ) +-LINK_LIBRARIES ( ${TK_STUB_LIBRARY} ) ++LINK_LIBRARIES ( ${TCL_LIBRARY} ) ++LINK_LIBRARIES ( ${TK_LIBRARY} ) + IF ( WIN32 AND NO_MSVCRT ) + STRING ( REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} ) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/cmake/SuperBuild.cmake ngsolve-6.2.1901/external_dependencies/netgen/cmake/SuperBuild.cmake --- ngsolve-6.2.1810/external_dependencies/netgen/cmake/SuperBuild.cmake 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/cmake/SuperBuild.cmake 2019-01-12 00:19:01.000000000 +0000 @@ -140,6 +140,8 @@ INTEL_MIC CMAKE_PREFIX_PATH CMAKE_INSTALL_PREFIX + ENABLE_UNIT_TESTS + ENABLE_CPP_CORE_GUIDELINES_CHECK ) # propagate all variables set on the command line using cmake -DFOO=BAR diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -17,6 +17,8 @@ option( INSTALL_PROFILES "install environment variable settings to /etc/profile.d" OFF ) option( USE_CCACHE "use ccache") option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON) +option( ENABLE_UNIT_TESTS "Enable Catch unit tests") +option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ngcore" OFF) option( USE_SUPERBUILD "use ccache" ON) @@ -341,8 +343,27 @@ enable_testing() include(CTest) +if(ENABLE_UNIT_TESTS) + include(${CMAKE_CURRENT_LIST_DIR}/cmake/external_projects/catch.cmake) +endif(ENABLE_UNIT_TESTS) + + ####################################################################### +if(ENABLE_CPP_CORE_GUIDELINES_CHECK) + find_program( + CLANG_TIDY_EXE + NAMES "clang-tidy" + DOC "Path to clang-tidy executable" + ) + if(NOT CLANG_TIDY_EXE) + message(WARNING "clang-tidy not found.") + else() + message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=libsrc/core/") + endif() +endif(ENABLE_CPP_CORE_GUIDELINES_CHECK) + add_subdirectory(libsrc) add_subdirectory(ng) add_subdirectory(tutorials) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/.gitlab-ci.yml ngsolve-6.2.1901/external_dependencies/netgen/.gitlab-ci.yml --- ngsolve-6.2.1810/external_dependencies/netgen/.gitlab-ci.yml 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/.gitlab-ci.yml 2019-01-12 00:19:01.000000000 +0000 @@ -5,25 +5,10 @@ - cleanup ############################################ -# System templates -############################################ - # Windows -.template_windows_32: &win32 - tags: - - windows - - x86 - before_script: - - "echo off" - - 'call "%VS140COMNTOOLS%\..\..\VC\bin\vcvars32.bat"' - - set CMAKE_GENERATOR=Visual Studio 14 2015 - - set CI_DIR=C:\ci\%CI_BUILD_REF%_32 - - set NETGEN_BUILD_DIR=%CI_DIR%\build - - set INSTALL_DIR=%CI_DIR%\install - - set NETGENDIR=%INSTALL_DIR%\bin - - set PYTHONPATH=%INSTALL_DIR%\lib\site-packages +############################################ -.template_windows_64: &win64 +.template_windows: &win tags: - windows - x64 @@ -31,37 +16,14 @@ - "echo off" - 'call "%VS140COMNTOOLS%\..\..\VC\bin\amd64\vcvars64.bat"' - set CMAKE_GENERATOR=Visual Studio 14 2015 Win64 - - set CI_DIR=C:\ci\%CI_BUILD_REF%_64 + - set CI_DIR=C:\ci\%CI_PIPELINE_ID% - set NETGEN_BUILD_DIR=%CI_DIR%\build - set INSTALL_DIR=%CI_DIR%\install - set NETGENDIR=%INSTALL_DIR%\bin - set PYTHONPATH=%INSTALL_DIR%\lib\site-packages -# Linux -.template_ubuntu: &ubuntu - tags: - - linux - before_script: - - pwd - - ls - - docker info - -.template_ubuntu_1510: &ubuntu_1510 - <<: *ubuntu - variables: - UBUNTU_VERSION: "15.10" - -.template_ubuntu_1604: &ubuntu_1604 - <<: *ubuntu - variables: - UBUNTU_VERSION: "16.04" - -############################################ -# Build stage -############################################ - -# Windows -.template_build_win: &tbuild_netgen_win +build_win: + <<: *win stage: build script: - git submodule update --init --recursive @@ -76,81 +38,131 @@ -DCMAKE_BUILD_TYPE=Release - cmake --build . --target INSTALL --config Release -.build_netgen_win32: - <<: *win32 - <<: *tbuild_netgen_win - cache: - paths: - - build/ - - src/ - key: "netgen_win32_${CI_BUILD_REF_NAME}" - -build_netgen_win64: - <<: *win64 - <<: *tbuild_netgen_win - cache: - paths: - - build/ - - src/ - key: "netgen_win64_${CI_BUILD_REF_NAME}" +test_win: + <<: *win + stage: test + script: + - cd %NETGEN_BUILD_DIR%\netgen + - ctest -C Release -V + - cd .. + +cleanup_win: + <<: *win + stage: cleanup + tags: + - windows + - x64 + script: + - cd %CI_PROJECT_DIR% + - rd /s /q %CI_DIR% + when: always + allow_failure: true + +############################################ +# Ubuntu/Linux +############################################ -# Linux -.template_build_linux: &build_linux +.template_ubuntu: &ubuntu + tags: + - linux + before_script: + - pwd + - ls + - docker info + variables: + UBUNTU_VERSION: "18.04" + +build_ubuntu: + <<: *ubuntu stage: build script: - - docker build -t netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} -f tests/docker_${UBUNTU_VERSION} . + - docker build -t netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} -f tests/dockerfile . - rm -f netgen_${CI_BUILD_REF_NAME}_$UBUNTU_VERSION.id - docker run --cidfile netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id -e CCACHE_DIR=/ccache -v /mnt/ccache:/ccache netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} bash /root/src/netgen/tests/build.sh - docker commit `cat netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id` netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} - rm netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id -.build_ubuntu_1510: - <<: *ubuntu_1510 - <<: *build_linux +test_ubuntu: + <<: *ubuntu + stage: test + script: + - >- + docker run + -e NETGENDIR=/opt/netgen/bin + -e PYTHONPATH=/opt/netgen/lib/python3/dist-packages + netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} + bash -c 'cd /root/build/netgen && make test_netgen ARGS="-V"' -build_ubuntu_1604: - <<: *ubuntu_1604 - <<: *build_linux +# cpp guideline checks +test_guidelines: + <<: *ubuntu + stage: test + script: + - docker run -e CCACHE_DIR=/ccache -v /mnt/ccache:/ccache netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} bash /root/src/netgen/tests/build_guidelines.sh + when: always +cleanup_ubuntu: + stage: cleanup + tags: + - linux + script: + # remove intermediate and old docker images and containers + - docker rm -f `docker ps --no-trunc -aq` + - docker images --no-trunc -aqf "dangling=true" | xargs docker rmi -f || true + when: always + allow_failure: true ############################################ -# Test stage +# MacOSX ############################################ -# Windows -.template_test_win: &test_win - stage: test - script: - - cd %NETGEN_BUILD_DIR%/netgen - - ctest -C Release -V - - cd .. +.template_mac: &mac + tags: + - mac + before_script: + - export ROOT_DIR=/tmp/$CI_PIPELINE_ID + - export SRC_DIR=$ROOT_DIR/src + - export BUILD_DIR=$ROOT_DIR/build + - export CMAKE_INSTALL_PREFIX=/tmp/$CI_PIPELINE_ID/install/Netgen.app + - export PYTHONPATH=$CMAKE_INSTALL_PREFIX/Contents/Resources/`python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))"`:. + - export PATH=$CMAKE_INSTALL_PREFIX/Contents/MacOS:$PATH -# skip since we have no machine with 32 bits -.test_win32: - <<: *win32 - <<: *test_win - -test_win64: - <<: *win64 - <<: *test_win +build_mac: + <<: *mac + stage: build + script: + - git submodule update --init --recursive + - rm -rf $BUILD_DIR + - mkdir -p $BUILD_DIR + - rm -rf $SRC_DIR + - mkdir -p $SRC_DIR + - cp -a . $SRC_DIR/ + - cd $BUILD_DIR + - >- + cmake $SRC_DIR + -DCMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX + -DCMAKE_BUILD_TYPE=Release + -DUSE_NATIVE_ARCH=OFF + -DUSE_CCACHE=ON + -DENABLE_UNIT_TESTS=ON + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 + -DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk + - make -j5 install -# Linux -.template_test_linux: &test_linux +test_mac: + <<: *mac stage: test script: - - >- - docker run - -e NETGENDIR=/opt/netgen/bin - -e PYTHONPATH=/opt/netgen/lib/python3/dist-packages - netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} - bash -c 'cd /root/build/netgen && make test_netgen ARGS="-V"' + - cd $BUILD_DIR/netgen + - ctest . --output-on-failure -.test_ubuntu_1510: - <<: *ubuntu_1510 - <<: *test_linux -test_ubuntu_1604: - <<: *ubuntu_1604 - <<: *test_linux +cleanup_mac: + <<: *mac + stage: cleanup + script: + - rm -rf $ROOT_DIR + when: always + allow_failure: true ############################################ # Deploy stage @@ -171,43 +183,3 @@ - git push github master only: - master - -############################################ -# Cleanup stage -############################################ - -linux_cleanup: - stage: cleanup - tags: - - linux - script: - # remove intermediate and old docker images and containers - - docker rm -f `docker ps --no-trunc -aq` - - docker images --no-trunc -aqf "dangling=true" | xargs docker rmi -f - when: always - allow_failure: true - -win64_cleanup: - <<: *win64 - stage: cleanup - tags: - - windows - - x64 - script: - - cd %CI_PROJECT_DIR% - - rd /s /q %CI_DIR% - when: always - allow_failure: true - -.win32_cleanup: - <<: *win32 - stage: cleanup - tags: - - windows - - x86 - script: - - cd %CI_PROJECT_DIR% - - rd /s /q %CI_DIR% - when: always - allow_failure: true - diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/libsrc/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -1,3 +1,4 @@ +add_subdirectory(core) add_subdirectory(general) add_subdirectory(gprim) add_subdirectory(linalg) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/archive.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/archive.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/archive.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/archive.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,52 @@ + +#include "archive.hpp" + +#ifndef WIN32 +#include +#endif + +namespace ngcore +{ + // clang-tidy should ignore this static object + static std::map library_versions; // NOLINT + std::map& Archive :: GetLibraryVersions() + { + return library_versions; + } + const VersionInfo& GetLibraryVersion(const std::string& library) + { return library_versions[library]; } + + void SetLibraryVersion(const std::string& library, const VersionInfo& version) + { library_versions[library] = version; } + +#ifdef WIN32 + // windows does demangling in typeid(T).name() + std::string Demangle(const char* typeinfo) { return typeinfo; } +#else + std::string Demangle(const char* typeinfo) { int status; return abi::__cxa_demangle(typeinfo, + nullptr, + nullptr, + &status); } +#endif + + // clang-tidy should ignore this static object + static std::unique_ptr> type_register; // NOLINT + const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname) + { + if(type_register == nullptr) type_register = + std::make_unique>(); + return (*type_register)[classname]; + } + void Archive :: SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info) + { + if(type_register == nullptr) type_register = + std::make_unique>(); + (*type_register)[classname] = info; + } + bool Archive :: IsRegistered(const std::string& classname) + { + if(type_register == nullptr) type_register = + std::make_unique>(); + return type_register->count(classname) != 0; + } +} // namespace ngcore diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/archive.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/archive.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/archive.hpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/archive.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,797 @@ +#ifndef NETGEN_CORE_ARCHIVE_HPP +#define NETGEN_CORE_ARCHIVE_HPP + +#include // for complex +#include // for size_t, strlen +#include // for operator<<, ifstream, ofstream, basic... +#include // for function +#include // for map, _Rb_tree_iterator +#include // for __shared_ptr_access, __shared_ptr_acc... +#include // for runtime_error +#include // for string, operator+ +#include // for declval, enable_if, false_type, is_co... +#include // for type_info +#include // for move, swap, pair +#include // for vector + +#include "ngcore_api.hpp" // for NGCORE_API, unlikely +#include "type_traits.hpp" // for all_of_tmpl +#include "version.hpp" // for VersionInfo + +namespace ngcore +{ + // Libraries using this archive can store their version here to implement backwards compatibility + NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library); + NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version); + NGCORE_API std::string Demangle(const char* typeinfo); + + class NGCORE_API Archive; + + namespace detail + { + // create new pointer of type T if it is default constructible, else throw + template + T* constructIfPossible_impl(Rest... /*unused*/) + { throw std::runtime_error(std::string(Demangle(typeid(T).name())) + " is not default constructible!"); } + + template::value>::type> + T* constructIfPossible_impl(int /*unused*/) { return new T; } // NOLINT + + template + T* constructIfPossible() { return constructIfPossible_impl(int{}); } + + //Type trait to check if a class implements a 'void DoArchive(Archive&)' function + template + struct has_DoArchive + { + private: + template + static constexpr auto check(T2*) -> + typename std::is_same().DoArchive(std::declval())),void>::type; + template + static constexpr std::false_type check(...); + using type = decltype(check(nullptr)); // NOLINT + public: + NGCORE_API static constexpr bool value = type::value; + }; + + // Check if class is archivable + template + struct is_Archivable_struct + { + private: + template + static constexpr auto check(T2*) -> + typename std::is_same() & std::declval()),Archive&>::type; + template + static constexpr std::false_type check(...); + using type = decltype(check(nullptr)); // NOLINT + public: + NGCORE_API static constexpr bool value = type::value; + }; + + struct ClassArchiveInfo + { + // create new object of this type and return a void* pointer that is points to the location + // of the (base)class given by type_info + std::function creator; + // This caster takes a void* pointer to the type stored in this info and casts it to a + // void* pointer pointing to the (base)class type_info + std::function upcaster; + // This caster takes a void* pointer to the (base)class type_info and returns void* pointing + // to the type stored in this info + std::function downcaster; + }; + } // namespace detail + + template + constexpr bool is_archivable = detail::is_Archivable_struct::value; + + // Base Archive class + class NGCORE_API Archive + { + const bool is_output; + // how many different shared_ptr/pointer have been (un)archived + int shared_ptr_count, ptr_count; + // maps for archived shared pointers and pointers + std::map shared_ptr2nr, ptr2nr; + // vectors for storing the unarchived (shared) pointers + std::vector> nr2shared_ptr; + std::vector nr2ptr; + + public: + Archive() = delete; + Archive(const Archive&) = delete; + Archive(Archive&&) = delete; + Archive (bool ais_output) : + is_output(ais_output), shared_ptr_count(0), ptr_count(0) { ; } + + virtual ~Archive() { ; } + + Archive& operator=(const Archive&) = delete; + Archive& operator=(Archive&&) = delete; + + bool Output () const { return is_output; } + bool Input () const { return !is_output; } + virtual const VersionInfo& GetVersion(const std::string& library) + { return GetLibraryVersions()[library]; } + + // Pure virtual functions that have to be implemented by In-/OutArchive + virtual Archive & operator & (double & d) = 0; + virtual Archive & operator & (int & i) = 0; + virtual Archive & operator & (long & i) = 0; + virtual Archive & operator & (size_t & i) = 0; + virtual Archive & operator & (short & i) = 0; + virtual Archive & operator & (unsigned char & i) = 0; + virtual Archive & operator & (bool & b) = 0; + virtual Archive & operator & (std::string & str) = 0; + virtual Archive & operator & (char *& str) = 0; + + virtual Archive & operator & (VersionInfo & version) + { + if(Output()) + (*this) << version.to_string(); + else + { + std::string s; + (*this) & s; + version = VersionInfo(s); + } + return *this; + } + + // Archive std classes ================================================ + template + Archive& operator & (std::complex& c) + { + if(Output()) + (*this) << c.real() << c.imag(); + else + { + T tmp; + (*this) & tmp; + c.real(tmp); + (*this) & tmp; + c.imag(tmp); + } + return (*this); + } + template + Archive& operator & (std::vector& v) + { + size_t size; + if(Output()) + size = v.size(); + (*this) & size; + if(Input()) + v.resize(size); + Do(&v[0], size); + return (*this); + } + template + Archive& operator& (std::map& map) + { + if(Output()) + { + (*this) << size_t(map.size()); + for(auto& pair : map) + (*this) << pair.first << pair.second; + } + else + { + size_t size = 0; + (*this) & size; + T1 key; T2 val; + for(size_t i = 0; i < size; i++) + { + T1 key; T2 val; + (*this) & key & val; + map[key] = val; + } + } + return (*this); + } + // Archive arrays ===================================================== + // this functions can be overloaded in Archive implementations for more efficiency + template >::type> + Archive & Do (T * data, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (double * d, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (int * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (long * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (size_t * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (short * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (unsigned char * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT + + virtual Archive & Do (bool * b, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; }; // NOLINT + + // Archive a class implementing a (void DoArchive(Archive&)) method ======= + template::value>> + Archive& operator & (T& val) + { + val.DoArchive(*this); return *this; + } + + // Archive shared_ptrs ================================================= + template + Archive& operator & (std::shared_ptr& ptr) + { + if(Output()) + { + // save -2 for nullptr + if(!ptr) + return (*this) << -2; + + void* reg_ptr = ptr.get(); + bool neededDowncast = false; + // Downcasting is only possible for our registered classes + if(typeid(T) != typeid(*ptr)) + { + if(!IsRegistered(Demangle(typeid(*ptr).name()))) + throw std::runtime_error(std::string("Archive error: Polymorphic type ") + + Demangle(typeid(*ptr).name()) + + " not registered for archive"); + reg_ptr = GetArchiveRegister(Demangle(typeid(*ptr).name())).downcaster(typeid(T), ptr.get()); + // if there was a true downcast we have to store more information + if(reg_ptr != static_cast(ptr.get()) ) + neededDowncast = true; + } + auto pos = shared_ptr2nr.find(reg_ptr); + // if not found store -1 and the pointer + if(pos == shared_ptr2nr.end()) + { + auto p = ptr.get(); + (*this) << -1; + (*this) & neededDowncast & p; + // if we did downcast we store the true type as well + if(neededDowncast) + (*this) << Demangle(typeid(*ptr).name()); + shared_ptr2nr[reg_ptr] = shared_ptr_count++; + return *this; + } + // if found store the position and if it has to be downcasted and how + (*this) << pos->second << neededDowncast; + if(neededDowncast) + (*this) << Demangle(typeid(*ptr).name()); + } + else // Input + { + int nr; + (*this) & nr; + // -2 restores a nullptr + if(nr == -2) + { + ptr = nullptr; + return *this; + } + // -1 restores a new shared ptr by restoring the inner pointer and creating a shared_ptr to it + if (nr == -1) + { + T* p = nullptr; + bool neededDowncast; + (*this) & neededDowncast & p; + ptr = std::shared_ptr(p); + // if we did downcast we need to store a shared_ptr to the true object + if(neededDowncast) + { + std::string name; + (*this) & name; + auto info = GetArchiveRegister(name); + // for this we use an aliasing constructor to create a shared pointer sharing lifetime + // with our shared ptr, but pointing to the true object + nr2shared_ptr.push_back(std::shared_ptr(std::static_pointer_cast(ptr), + info.downcaster(typeid(T), + ptr.get()))); + } + else + nr2shared_ptr.push_back(ptr); + } + else + { + auto other = nr2shared_ptr[nr]; + bool neededDowncast; + (*this) & neededDowncast; + if(neededDowncast) + { + // if there was a downcast we can expect the class to be registered (since archiving + // wouldn't have worked else) + std::string name; + (*this) & name; + auto info = GetArchiveRegister(name); + // same trick as above, create a shared ptr sharing lifetime with + // the shared_ptr in the register, but pointing to our object + ptr = std::static_pointer_cast(std::shared_ptr(other, + info.upcaster(typeid(T), + other.get()))); + } + else + ptr = std::static_pointer_cast(other); + } + } + return *this; + } + + // Archive pointers ======================================================= + template + Archive & operator& (T *& p) + { + if (Output()) + { + // if the pointer is null store -2 + if (!p) + return (*this) << -2; + auto reg_ptr = static_cast(p); + if(typeid(T) != typeid(*p)) + { + if(!IsRegistered(Demangle(typeid(*p).name()))) + throw std::runtime_error(std::string("Archive error: Polymorphic type ") + + Demangle(typeid(*p).name()) + + " not registered for archive"); + reg_ptr = GetArchiveRegister(Demangle(typeid(*p).name())).downcaster(typeid(T), static_cast(p)); + } + auto pos = ptr2nr.find(reg_ptr); + // if the pointer is not found in the map create a new entry + if (pos == ptr2nr.end()) + { + ptr2nr[reg_ptr] = ptr_count++; + if(typeid(*p) == typeid(T)) + if (std::is_constructible::value) + { + return (*this) << -1 & (*p); + } + else + throw std::runtime_error(std::string("Archive error: Class ") + + Demangle(typeid(*p).name()) + " does not provide a default constructor!"); + else + { + // if a pointer to a base class is archived, the class hierarchy must be registered + // to avoid compile time issues we allow this behaviour only for "our" classes that + // implement a void DoArchive(Archive&) member function + // To recreate the object we need to store the true type of it + if(!IsRegistered(Demangle(typeid(*p).name()))) + throw std::runtime_error(std::string("Archive error: Polymorphic type ") + + Demangle(typeid(*p).name()) + + " not registered for archive"); + return (*this) << -3 << Demangle(typeid(*p).name()) & (*p); + } + } + else + { + (*this) & pos->second; + bool downcasted = !(reg_ptr == static_cast(p) ); + // store if the class has been downcasted and the name + (*this) << downcasted << Demangle(typeid(*p).name()); + } + } + else + { + int nr; + (*this) & nr; + if (nr == -2) // restore a nullptr + p = nullptr; + else if (nr == -1) // create a new pointer of standard type (no virtual or multiple inheritance,...) + { + p = detail::constructIfPossible(); + nr2ptr.push_back(p); + (*this) & *p; + } + else if(nr == -3) // restore one of our registered classes that can have multiple inheritance,... + { + // As stated above, we want this special behaviour only for our classes that implement DoArchive + std::string name; + (*this) & name; + auto info = GetArchiveRegister(name); + // the creator creates a new object of type name, and returns a void* pointing + // to T (which may have an offset) + p = static_cast(info.creator(typeid(T))); + // we store the downcasted pointer (to be able to find it again from + // another class in a multiple inheritance tree) + nr2ptr.push_back(info.downcaster(typeid(T),p)); + (*this) & *p; + } + else + { + bool downcasted; + std::string name; + (*this) & downcasted & name; + if(downcasted) + { + // if the class has been downcasted we can assume it is in the register + auto info = GetArchiveRegister(name); + p = static_cast(info.upcaster(typeid(T), nr2ptr[nr])); + } + else + p = static_cast(nr2ptr[nr]); + } + } + return *this; + } + + // const ptr + template + Archive& operator &(const T*& t) + { + return (*this) & const_cast(t); // NOLINT + } + + // Write a read only variable + template + Archive & operator << (const T & t) + { + T ht(t); + (*this) & ht; + return *this; + } + + virtual void FlushBuffer() {} + + protected: + static std::map& GetLibraryVersions(); + + private: + template + friend class RegisterClassForArchive; + + // Returns ClassArchiveInfo of Demangled typeid + static const detail::ClassArchiveInfo& GetArchiveRegister(const std::string& classname); + // Set ClassArchiveInfo for Demangled typeid, this is done by creating an instance of + // RegisterClassForArchive + static void SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info); + static bool IsRegistered(const std::string& classname); + + // Helper class for up-/downcasting + template + struct Caster{}; + + template + struct Caster + { + static void* tryUpcast (const std::type_info& /*unused*/, T* /*unused*/) + { + throw std::runtime_error("Upcast not successful, some classes are not registered properly for archiving!"); + } + static void* tryDowncast (const std::type_info& /*unused*/, void* /*unused*/) + { + throw std::runtime_error("Downcast not successful, some classes are not registered properly for archiving!"); + } + }; + + template + struct Caster + { + static void* tryUpcast(const std::type_info& ti, T* p) + { + try + { return GetArchiveRegister(Demangle(typeid(B1).name())). + upcaster(ti, static_cast(dynamic_cast(p))); } + catch(std::exception&) + { return Caster::tryUpcast(ti, p); } + } + + static void* tryDowncast(const std::type_info& ti, void* p) + { + if(typeid(B1) == ti) + return dynamic_cast(static_cast(p)); + try + { + return dynamic_cast(static_cast(GetArchiveRegister(Demangle(typeid(B1).name())). + downcaster(ti, p))); + } + catch(std::exception&) + { + return Caster::tryDowncast(ti, p); + } + } + }; + }; + + template + class RegisterClassForArchive + { + public: + RegisterClassForArchive() + { + static_assert(detail::all_of_tmpl::value...>, + "Variadic template arguments must be base classes of T"); + detail::ClassArchiveInfo info; + info.creator = [this,&info](const std::type_info& ti) -> void* + { return typeid(T) == ti ? detail::constructIfPossible() + : Archive::Caster::tryUpcast(ti, detail::constructIfPossible()); }; + info.upcaster = [this](const std::type_info& ti, void* p) -> void* + { return typeid(T) == ti ? p : Archive::Caster::tryUpcast(ti, static_cast(p)); }; + info.downcaster = [this](const std::type_info& ti, void* p) -> void* + { return typeid(T) == ti ? p : Archive::Caster::tryDowncast(ti, p); }; + Archive::SetArchiveRegister(std::string(Demangle(typeid(T).name())),info); + } + + + }; + + // BinaryOutArchive ====================================================================== + class NGCORE_API BinaryOutArchive : public Archive + { + static constexpr size_t BUFFERSIZE = 1024; + char buffer[BUFFERSIZE] = {}; + size_t ptr = 0; + std::shared_ptr fout; + public: + BinaryOutArchive() = delete; + BinaryOutArchive(const BinaryOutArchive&) = delete; + BinaryOutArchive(BinaryOutArchive&&) = delete; + BinaryOutArchive(std::shared_ptr&& afout) + : Archive(true), fout(std::move(afout)) + { + (*this) & GetLibraryVersions(); + } + BinaryOutArchive(const std::string& filename) + : BinaryOutArchive(std::make_shared(filename)) {} + ~BinaryOutArchive () override { FlushBuffer(); } + + BinaryOutArchive& operator=(const BinaryOutArchive&) = delete; + BinaryOutArchive& operator=(BinaryOutArchive&&) = delete; + + const VersionInfo& GetVersion(const std::string& library) override + { return GetLibraryVersions()[library]; } + + using Archive::operator&; + Archive & operator & (double & d) override + { return Write(d); } + Archive & operator & (int & i) override + { return Write(i); } + Archive & operator & (short & i) override + { return Write(i); } + Archive & operator & (long & i) override + { return Write(i); } + Archive & operator & (size_t & i) override + { return Write(i); } + Archive & operator & (unsigned char & i) override + { return Write(i); } + Archive & operator & (bool & b) override + { return Write(b); } + Archive & operator & (std::string & str) override + { + int len = str.length(); + (*this) & len; + FlushBuffer(); + if(len) + fout->write (&str[0], len); + return *this; + } + Archive & operator & (char *& str) override + { + long len = str ? strlen (str) : -1; + (*this) & len; + FlushBuffer(); + if(len > 0) + fout->write (&str[0], len); // NOLINT + return *this; + } + void FlushBuffer() override + { + if (ptr > 0) + { + fout->write(&buffer[0], ptr); + ptr = 0; + } + } + + private: + template + Archive & Write (T x) + { + if (unlikely(ptr > BUFFERSIZE-sizeof(T))) + { + fout->write(&buffer[0], ptr); + *reinterpret_cast(&buffer[0]) = x; // NOLINT + ptr = sizeof(T); + return *this; + } + *reinterpret_cast(&buffer[ptr]) = x; // NOLINT + ptr += sizeof(T); + return *this; + } + }; + + // BinaryInArchive ====================================================================== + class NGCORE_API BinaryInArchive : public Archive + { + std::map vinfo{}; + std::shared_ptr fin; + public: + BinaryInArchive (std::shared_ptr&& afin) + : Archive(false), fin(std::move(afin)) + { + (*this) & vinfo; + } + BinaryInArchive (const std::string& filename) + : BinaryInArchive(std::make_shared(filename)) { ; } + + const VersionInfo& GetVersion(const std::string& library) override + { return vinfo[library]; } + + using Archive::operator&; + Archive & operator & (double & d) override + { Read(d); return *this; } + Archive & operator & (int & i) override + { Read(i); return *this; } + Archive & operator & (short & i) override + { Read(i); return *this; } + Archive & operator & (long & i) override + { Read(i); return *this; } + Archive & operator & (size_t & i) override + { Read(i); return *this; } + Archive & operator & (unsigned char & i) override + { Read(i); return *this; } + Archive & operator & (bool & b) override + { Read(b); return *this; } + Archive & operator & (std::string & str) override + { + int len; + (*this) & len; + str.resize(len); + if(len) + fin->read(&str[0], len); // NOLINT + return *this; + } + Archive & operator & (char *& str) override + { + long len; + (*this) & len; + if(len == -1) + str = nullptr; + else + { + str = new char[len+1]; // NOLINT + fin->read(&str[0], len); // NOLINT + str[len] = '\0'; // NOLINT + } + return *this; + } + + Archive & Do (double * d, size_t n) override + { fin->read(reinterpret_cast(d), n*sizeof(double)); return *this; } // NOLINT + Archive & Do (int * i, size_t n) override + { fin->read(reinterpret_cast(i), n*sizeof(int)); return *this; } // NOLINT + Archive & Do (size_t * i, size_t n) override + { fin->read(reinterpret_cast(i), n*sizeof(size_t)); return *this; } // NOLINT + + private: + template + inline void Read(T& val) + { fin->read(reinterpret_cast(&val), sizeof(T)); } // NOLINT + }; + + // TextOutArchive ====================================================================== + class NGCORE_API TextOutArchive : public Archive + { + std::shared_ptr fout; + public: + TextOutArchive (std::shared_ptr&& afout) + : Archive(true), fout(std::move(afout)) + { + (*this) & GetLibraryVersions(); + } + TextOutArchive (const std::string& filename) : + TextOutArchive(std::make_shared(filename)) { } + + const VersionInfo& GetVersion(const std::string& library) override + { return GetLibraryVersions()[library]; } + + using Archive::operator&; + Archive & operator & (double & d) override + { *fout << d << '\n'; return *this; } + Archive & operator & (int & i) override + { *fout << i << '\n'; return *this; } + Archive & operator & (short & i) override + { *fout << i << '\n'; return *this; } + Archive & operator & (long & i) override + { *fout << i << '\n'; return *this; } + Archive & operator & (size_t & i) override + { *fout << i << '\n'; return *this; } + Archive & operator & (unsigned char & i) override + { *fout << int(i) << '\n'; return *this; } + Archive & operator & (bool & b) override + { *fout << (b ? 't' : 'f') << '\n'; return *this; } + Archive & operator & (std::string & str) override + { + int len = str.length(); + *fout << len << '\n'; + if(len) + { + fout->write(&str[0], len); // NOLINT + *fout << '\n'; + } + return *this; + } + Archive & operator & (char *& str) override + { + long len = str ? strlen (str) : -1; + *this & len; + if(len > 0) + { + fout->write (&str[0], len); // NOLINT + *fout << '\n'; + } + return *this; + } + }; + + // TextInArchive ====================================================================== + class NGCORE_API TextInArchive : public Archive + { + std::map vinfo{}; + std::shared_ptr fin; + public: + TextInArchive (std::shared_ptr&& afin) : + Archive(false), fin(std::move(afin)) + { + (*this) & vinfo; + } + TextInArchive (const std::string& filename) + : TextInArchive(std::make_shared(filename)) {} + + const VersionInfo& GetVersion(const std::string& library) override + { return vinfo[library]; } + + using Archive::operator&; + Archive & operator & (double & d) override + { *fin >> d; return *this; } + Archive & operator & (int & i) override + { *fin >> i; return *this; } + Archive & operator & (short & i) override + { *fin >> i; return *this; } + Archive & operator & (long & i) override + { *fin >> i; return *this; } + Archive & operator & (size_t & i) override + { *fin >> i; return *this; } + Archive & operator & (unsigned char & i) override + { int _i; *fin >> _i; i = _i; return *this; } + Archive & operator & (bool & b) override + { char c; *fin >> c; b = (c=='t'); return *this; } + Archive & operator & (std::string & str) override + { + int len; + *fin >> len; + char ch; + fin->get(ch); // '\n' + str.resize(len); + if(len) + fin->get(&str[0], len+1, '\0'); + return *this; + } + Archive & operator & (char *& str) override + { + long len; + (*this) & len; + char ch; + if(len == -1) + { + str = nullptr; + return (*this); + } + str = new char[len+1]; // NOLINT + if(len) + { + fin->get(ch); // \n + fin->get(&str[0], len+1, '\0'); // NOLINT + } + str[len] = '\0'; // NOLINT + return *this; + } + }; +} // namespace ngcore + +#endif // NETGEN_CORE_ARCHIVE_HPP diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/.clang-tidy ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/.clang-tidy --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/.clang-tidy 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/.clang-tidy 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,5 @@ +Checks: '*,-clang-analyzer-alpha.*,-*braces-around-statements,-fuchsia-*,-google-runtime-references,-readability-implicit-bool-conversion,-google-explicit-constructor,-hicpp-explicit-conversions,-google-runtime-int,-llvm-header-guard' +CheckOptions: + - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor + value: 1 +WarningsAsErrors: '*' \ No newline at end of file diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,12 @@ +add_library(ngcore SHARED archive.cpp) + +target_compile_definitions(ngcore PRIVATE -DNGCORE_EXPORTS) + +install(TARGETS ngcore DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen) + +install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel) + +if(ENABLE_CPP_CORE_GUIDELINES_CHECK) + set_target_properties(ngcore PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}") +endif(ENABLE_CPP_CORE_GUIDELINES_CHECK) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/ngcore_api.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/ngcore_api.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/ngcore_api.hpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/ngcore_api.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,29 @@ +#ifndef NETGEN_CORE_NGCORE_API_HPP +#define NETGEN_CORE_NGCORE_API_HPP + +#ifdef WIN32 + #define NGCORE_API_EXPORT __declspec(dllexport) + #define NGCORE_API_IMPORT __declspec(dllimport) +#else + #define NGCORE_API_EXPORT + #define NGCORE_API_IMPORT +#endif + +#ifdef NGCORE_EXPORTS + #define NGCORE_API NGCORE_API_EXPORT +#else + #define NGCORE_API NGCORE_API_IMPORT +#endif + +namespace ngcore +{ +#if defined(__GNUC__) + inline bool likely (bool x) { return bool(__builtin_expect(long(x), 1L)); } + inline bool unlikely (bool x) { return bool(__builtin_expect(long(x), 0L)); } +#else + inline bool likely (bool x) { return x; } + inline bool unlikely (bool x) { return x; } +#endif +} // namespace ngcore + +#endif // NETGEN_CORE_NGCORE_API_HPP diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/ngcore.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/ngcore.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/ngcore.hpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/ngcore.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,7 @@ +#ifndef NETGEN_CORE_NGCORE_HPP +#define NETGEN_CORE_NGCORE_HPP + +#include "archive.hpp" +#include "version.hpp" + +#endif // NETGEN_CORE_NGCORE_HPP diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/type_traits.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/type_traits.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/type_traits.hpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/type_traits.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,17 @@ +#ifndef NETGEN_CORE_TYPE_TRAITS_HPP +#define NETGEN_CORE_TYPE_TRAITS_HPP + +#include + +namespace ngcore +{ + namespace detail + { + template struct _BoolArray{}; + + template + constexpr bool all_of_tmpl = std::is_same<_BoolArray, _BoolArray<(vals || true)...>>::value; // NOLINT + } // namespace detail +} // namespace ngcore + +#endif // NETGEN_CORE_TYPE_TRAITS_HPP diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/version.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/version.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/core/version.hpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/core/version.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,88 @@ +#ifndef NETGEN_CORE_VERSION_HPP +#define NETGEN_CORE_VERSION_HPP + +#include +#include + +#include "ngcore_api.hpp" + +namespace ngcore +{ + class VersionInfo + { + private: + size_t mayor_{}, minor_{}, release{}, patch{}; + std::string git_hash{}; + public: + VersionInfo() = default; + VersionInfo(std::string vstring) + { + minor_ = release = patch = 0; + git_hash = ""; + if(vstring.substr(0,1) == "v") + vstring = vstring.substr(1,vstring.size()-1); + auto dot = vstring.find('.'); + mayor_ = std::stoi(vstring.substr(0,dot)); + if(dot == size_t(-1)) vstring = ""; + else vstring = vstring.substr(dot+1, vstring.size()-dot-1); + if(!vstring.empty()) + { + dot = vstring.find('.'); + minor_ = std::stoi(vstring.substr(0,dot)); + if (dot == size_t(-1)) vstring = ""; + else vstring = vstring.substr(dot+1, vstring.size()-dot-1); + if(!vstring.empty()) + { + dot = vstring.find('-'); + release = std::stoi(vstring.substr(0,dot)); + if(dot == size_t(-1)) vstring = ""; + else vstring = vstring.substr(dot+1,vstring.size()-dot-1); + if(!vstring.empty()) + { + dot = vstring.find('-'); + patch = std::stoi(vstring.substr(0,dot)); + if(dot == size_t(-1)) vstring = ""; + else vstring = vstring.substr(dot+1, vstring.size()-dot-1); + if(!vstring.empty()) + git_hash = vstring; + } + } + } + } + VersionInfo(const char* cstr) : VersionInfo(std::string(cstr)) { } + + std::string to_string() const + { std::string vstring = "v" + std::to_string(mayor_); + if(minor_ || release || patch || !git_hash.empty()) + { + vstring += "." + std::to_string(minor_); + if(release || patch || !git_hash.empty()) + { + vstring += "." + std::to_string(release); + if(patch || !git_hash.empty()) + { + vstring += "-" + std::to_string(patch); + if(!git_hash.empty()) + vstring += "-" + git_hash; + } + } + } + return vstring; + } + bool operator <(const VersionInfo& other) const + { + return std::tie(mayor_, minor_, release, patch) < + std::tie(other.mayor_, other.minor_, other.release, other.patch); + } + bool operator ==(const VersionInfo& other) const + { + return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release + && patch == other.patch; + } + bool operator >(const VersionInfo& other) const { return other < (*this); } + bool operator <=(const VersionInfo& other) const { return !((*this) > other); } + bool operator >=(const VersionInfo& other) const { return !((*this) < other); } + }; +} // namespace ngcore + +#endif // NETGEN_CORE_VERSION_HPP diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/algprim.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/algprim.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/algprim.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/algprim.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -1941,6 +1941,13 @@ << R << " " << r << endl; } - - +RegisterClassForArchive regqs; +RegisterClassForArchive regpl; +RegisterClassForArchive regsph; +RegisterClassForArchive regcyl; +RegisterClassForArchive regelcyl; +RegisterClassForArchive regell; +RegisterClassForArchive regcone; +RegisterClassForArchive regellcone; +RegisterClassForArchive regtorus; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/algprim.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/algprim.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/algprim.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/algprim.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -47,6 +47,11 @@ virtual void Print (ostream & str) const; virtual void Read (istream & ist); void PrintCoeff (ostream & ost) const; + virtual void DoArchive(Archive& ar) + { + OneSurfacePrimitive::DoArchive(ar); + ar & cxx & cyy & czz & cxy & cxz & cyz & cx & cy & cz & c1; + } }; @@ -64,6 +69,14 @@ public: /// Plane (const Point<3> & ap, Vec<3> an); + // default constructor for archive + Plane() {} + + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & p & n & eps_base; + } Point<3> P() const { return p; } Vec<3> N() const { return n; } virtual void GetPrimitiveData (const char *& classname, @@ -130,6 +143,14 @@ public: /// Sphere (const Point<3> & ac, double ar); + // default constructor for archive + Sphere() {} + + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & c & r & invr; + } virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; @@ -188,6 +209,14 @@ public: Cylinder (const Point<3> & aa, const Point<3> & ab, double ar); Cylinder (Array & coeffs); + // default constructor for archive + Cylinder() {} + + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & a & b & r & vab; + } Point<3> A() const { return a; } Point<3> B() const { return b; } double R() const { return r; } @@ -250,7 +279,14 @@ EllipticCylinder (const Point<3> & aa, const Vec<3> & avl, const Vec<3> & avs); EllipticCylinder (Array & coeffs); + // default constructor for archive + EllipticCylinder() {} + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & a & vl & vs & vab & t0vec & t1vec & vabl & t0 & t1; + } // static Primitive * CreateDefault (); virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; @@ -299,6 +335,14 @@ const Vec<3> & av1, const Vec<3> & av2, const Vec<3> & av3); + // default constructor for archive + Ellipsoid() {} + + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & a & v1 & v2 & v3 & rmin; + } /// virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; /// @@ -339,6 +383,14 @@ /// Cone (const Point<3> & aa, const Point<3> & ab, double ara, double arb); /// + // default constructor for archive + Cone() {} + + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & a & b & ra & rb & minr & vab & t0vec & t1vec & vabl & t0 & t1 & cosphi; + } static Primitive * CreateDefault (); virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; virtual void SetPrimitiveData (Array & coeffs); @@ -383,7 +435,14 @@ /// EllipticCone (const Point<3> & aa, const Vec<3> & avl, const Vec<3> & avs, double ah, double avlr); + // default constructor for archive + EllipticCone() {} + virtual void DoArchive(Archive& ar) + { + QuadraticSurface::DoArchive(ar); + ar & a & vl & vs & h & vlr; + } static Primitive * CreateDefault (); virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; virtual void SetPrimitiveData (Array & coeffs); @@ -425,6 +484,14 @@ public: /// OK Torus (const Point<3> & ac, const Vec<3> & an, double aR, double ar); + // default constructor for archive + Torus() {} + + virtual void DoArchive(Archive& ar) + { + OneSurfacePrimitive::DoArchive(ar); + ar & c & n & R & r; + } /// OK const Point<3> & Center () const { return c; } /// OK diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/brick.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/brick.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/brick.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/brick.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -523,4 +523,8 @@ surfaceactive.Elem(6) = (box.PMin()(0) < pmax(0)) && (pmax(0) < box.PMax()(0)); } + +RegisterClassForArchive regpar; +RegisterClassForArchive regbrick; +RegisterClassForArchive regob; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/brick.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/brick.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/brick.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/brick.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -28,8 +28,16 @@ public: Parallelogram3d (Point<3> ap1, Point<3> ap2, Point<3> ap3); + // default constructor for archive + Parallelogram3d() {} virtual ~Parallelogram3d (); + virtual void DoArchive(Archive& ar) + { + Surface::DoArchive(ar); + ar & p1 & p2 & p3 & p4 & v12 & v13 & n; + } + void SetPoints (Point<3> ap1, Point<3> ap2, Point<3> ap3); virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; @@ -60,7 +68,15 @@ public: Brick (Point<3> ap1, Point<3> ap2, Point<3> ap3, Point<3> ap4); + // default constructor for archive + Brick() {} virtual ~Brick (); + + virtual void DoArchive(Archive& ar) + { + Primitive::DoArchive(ar); + ar & p1 & p2 & p3 & p4 & v12 & v13 & v14 & faces; + } static Primitive * CreateDefault (); virtual Primitive * Copy () const; @@ -116,7 +132,15 @@ Point<3> pmin, pmax; public: OrthoBrick (const Point<3> & ap1, const Point<3> & ap2); - + // default constructor for archive + OrthoBrick() {} + + virtual void DoArchive(Archive& ar) + { + Brick::DoArchive(ar); + ar & pmin & pmax; + } + virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; virtual void Reduce (const BoxSphere<3> & box); }; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/csgeom.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/csgeom.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/csgeom.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/csgeom.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -324,6 +324,14 @@ } + void CSGeometry :: DoArchive(Archive& archive) + { + archive & surfaces & solids & toplevelobjects & userpoints & userpoints_ref_factor + & identpoints & boundingbox & isidenticto & ideps + & filename & spline_surfaces & splinecurves2d & splinecurves3d & surf2prim; + if(archive.Input()) + FindIdenticSurfaces(1e-6); + } void CSGeometry :: SaveSurfaces (ostream & out) const { @@ -1584,5 +1592,5 @@ }; CSGInit csginit; - + static RegisterClassForArchive regcsg; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/csgeom.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/csgeom.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/csgeom.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/csgeom.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -39,7 +39,14 @@ public: TopLevelObject (Solid * asolid, Surface * asurface = NULL); + // default constructor for archive + TopLevelObject() {} + void DoArchive(Archive& archive) + { + archive & solid & surface & red & blue & green & visible & transp & maxh + & material & layer & bc & bcname; + } const Solid * GetSolid() const { return solid; } Solid * GetSolid() { return solid; } @@ -124,6 +131,11 @@ UserPoint() = default; UserPoint (Point<3> p, int _index) : Point<3>(p), index(_index) { ; } int GetIndex() const { return index; } + void DoArchive(Archive& archive) + { + archive & index; + Point<3>::DoArchive(archive); + } }; private: @@ -165,14 +177,14 @@ void Clean (); - virtual void Save (string filename) const; + virtual void Save (string filename) const override; void Save (ostream & ost) const; void Load (istream & ist); void SaveSurfaces (ostream & out) const; void LoadSurfaces (istream & in); - virtual void SaveToMeshFile (ostream & ost) const; + virtual void SaveToMeshFile (ostream & ost) const override; int GetChangeVal() { return changeval; } void Change() { changeval++; } @@ -198,6 +210,8 @@ void SetSplineCurve (const char * name, SplineGeometry<3> * spl); const SplineGeometry<2> * GetSplineCurve2d (const string & name) const; const SplineGeometry<3> * GetSplineCurve3d (const string & name) const; + + void DoArchive(Archive& archive) override; void SetFlags (const char * solidname, const Flags & flags); @@ -330,9 +344,9 @@ Array bcmodifications; - virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam); + virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam) override; - virtual const Refinement & GetRefinement () const; + virtual const Refinement & GetRefinement () const override; void AddSplineSurface (shared_ptr ss) { spline_surfaces.Append(ss); } }; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/extrusion.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/extrusion.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/extrusion.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/extrusion.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -653,15 +653,15 @@ Extrusion :: Extrusion(const SplineGeometry<3> & path_in, const SplineGeometry<2> & profile_in, const Vec<3> & z_dir) : - path(path_in), profile(profile_in), z_direction(z_dir) + path(&path_in), profile(&profile_in), z_direction(z_dir) { surfaceactive.SetSize(0); surfaceids.SetSize(0); - for(int j=0; jGetNSplines(); j++) { - ExtrusionFace * face = new ExtrusionFace(&(profile.GetSpline(j)), - &path, + ExtrusionFace * face = new ExtrusionFace(&((*profile).GetSpline(j)), + path, z_direction); faces.Append(face); surfaceactive.Append(true); @@ -872,5 +872,6 @@ surfaceactive[i] = true; } - + RegisterClassForArchive regexf; + RegisterClassForArchive regextr; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/extrusion.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/extrusion.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/extrusion.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/extrusion.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -49,9 +49,18 @@ const Vec<3> & z_direction); ExtrusionFace(const Array & raw_data); - + // default constructor for archive + ExtrusionFace() {} ~ExtrusionFace(); + + virtual void DoArchive(Archive& ar) + { + Surface::DoArchive(ar); + ar & profile & path & glob_z_direction & deletable & spline3_path & line_path & + x_dir & y_dir & z_dir & loc_z_dir & p0 & profile_tangent & profile_par & + profile_spline_coeff & latest_seg & latest_t & latest_point2d & latest_point3d; + } virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; @@ -109,10 +118,10 @@ class Extrusion : public Primitive { private: - const SplineGeometry<3> & path; - const SplineGeometry<2> & profile; // closed, clockwise oriented curve + const SplineGeometry<3>* path; + const SplineGeometry<2>* profile; // closed, clockwise oriented curve - const Vec<3> & z_direction; + Vec<3> z_direction; Array faces; @@ -122,7 +131,15 @@ Extrusion(const SplineGeometry<3> & path_in, const SplineGeometry<2> & profile_in, const Vec<3> & z_dir); + // default constructor for archive + Extrusion() {} ~Extrusion(); + + virtual void DoArchive(Archive& ar) + { + Primitive::DoArchive(ar); + ar & path & profile & z_direction & faces & latestfacenum; + } virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; virtual INSOLID_TYPE PointInSolid (const Point<3> & p, double eps) const; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/python_csg.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/python_csg.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/python_csg.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/python_csg.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -360,37 +360,31 @@ py::class_> (m, "CSGeometry") .def(py::init<>()) - .def("__init__", - [](CSGeometry *instance, const string & filename) - { - cout << "load geometry"; - ifstream ist(filename); - ParseCSG(ist, instance); - instance -> FindIdenticSurfaces(1e-8 * instance->MaxSize()); - }) - .def("__init__", - [](CSGeometry *instance, const py::list & solidlist) - { - cout << "csg from list"; - new (instance) CSGeometry(); - for (int i = 0; i < len(solidlist); i++) - { - py::object obj = solidlist[i]; - cout << "obj " << i << endl; - - py::extract> solid(solidlist[i]); - if(solid.check()) - { - cout << "its a solid" << endl; - solid()->AddSurfaces (*instance); - solid()->GiveUpOwner(); - int tlonr = instance->SetTopLevelObject (solid()->GetSolid()); - instance->GetTopLevelObject(tlonr) -> SetMaterial(solid()->GetMaterial()); - } - } - instance -> FindIdenticSurfaces(1e-8 * instance->MaxSize()); - }) - + .def(py::init([](const string& filename) + { + ifstream ist (filename); + auto geo = make_shared(); + ParseCSG(ist, geo.get()); + geo->FindIdenticSurfaces(1e-8 * geo->MaxSize()); + return geo; + }), py::arg("filename")) + .def(py::pickle( + [](CSGeometry& self) + { + auto ss = make_shared(); + BinaryOutArchive archive(ss); + archive & self; + archive.FlushBuffer(); + return py::make_tuple(py::bytes(ss->str())); + }, + [](py::tuple state) + { + auto geo = make_shared(); + auto ss = make_shared (py::cast(state[0])); + BinaryInArchive archive(ss); + archive & (*geo); + return geo; + })) .def("Save", FunctionPointer([] (CSGeometry & self, string filename) { cout << "save geometry to file " << filename << endl; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/revolution.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/revolution.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/revolution.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/revolution.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -640,9 +640,9 @@ Revolution :: Revolution(const Point<3> & p0_in, const Point<3> & p1_in, const SplineGeometry<2> & spline_in) : - p0(p0_in), p1(p1_in), splinecurve(spline_in), - nsplines(spline_in.GetNSplines()) + p0(p0_in), p1(p1_in) { + auto nsplines = spline_in.GetNSplines(); surfaceactive.SetSize(0); surfaceids.SetSize(0); @@ -650,21 +650,21 @@ v_axis.Normalize(); - if(splinecurve.GetSpline(0).StartPI()(1) <= 0. && - splinecurve.GetSpline(nsplines-1).EndPI()(1) <= 0.) + if(spline_in.GetSpline(0).StartPI()(1) <= 0. && + spline_in.GetSpline(nsplines-1).EndPI()(1) <= 0.) type = 2; - else if (Dist(splinecurve.GetSpline(0).StartPI(), - splinecurve.GetSpline(nsplines-1).EndPI()) < 1e-7) + else if (Dist(spline_in.GetSpline(0).StartPI(), + spline_in.GetSpline(nsplines-1).EndPI()) < 1e-7) type = 1; else cerr << "Surface of revolution cannot be constructed" << endl; - for(int i=0; i regrevf; + RegisterClassForArchive regrev; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/revolution.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/revolution.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/revolution.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/revolution.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -45,9 +45,18 @@ const int id_in = 0); RevolutionFace(const Array & raw_data); + // default constructor for archive + RevolutionFace() {} ~RevolutionFace(); + virtual void DoArchive(Archive& ar) + { + Surface::DoArchive(ar); + ar & isfirst & islast & spline & deletable & p0 & v_axis & id & spline_coefficient + & spline_coefficient_shifted & checklines_vec & checklines_start & checklines_normal; + } + virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; virtual double CalcFunctionValue (const Point<3> & point) const; @@ -96,8 +105,6 @@ private: Point<3> p0,p1; Vec<3> v_axis; - const SplineGeometry<2> & splinecurve; - const int nsplines; // 1 ... torus-like // 2 ... sphere-like @@ -112,9 +119,16 @@ Revolution(const Point<3> & p0_in, const Point<3> & p1_in, const SplineGeometry<2> & spline_in); + // default constructor for archive + Revolution() {} ~Revolution(); - + + virtual void DoArchive(Archive& ar) + { + Primitive::DoArchive(ar); + ar & p0 & p1 & v_axis & type & faces & intersecting_face; + } /* Check, whether box intersects solid defined by surface. diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/solid.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/solid.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/solid.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/solid.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -55,8 +55,22 @@ public: Solid (Primitive * aprim); Solid (optyp aop, Solid * as1, Solid * as2 = NULL); + // default constructor for archive + Solid () {} ~Solid (); + void DoArchive(Archive& archive) + { + archive & name & prim & s1 & s2 & visited & maxh & num_surfs; + if(archive.Output()) + archive << int(op); + else + { + int iop; + archive & iop; + op = optyp(iop); + } + } const char * Name () const { return name; } void SetName (const char * aname); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/splinesurface.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/splinesurface.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/splinesurface.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/splinesurface.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -73,4 +73,5 @@ str << "SplineSurface with base " << *baseprimitive << endl; } + static RegisterClassForArchive regss; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/splinesurface.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/splinesurface.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/splinesurface.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/splinesurface.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -19,6 +19,8 @@ SplineSurface(shared_ptr abaseprimitive, shared_ptr>> acuts) : OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts) { ; } + // default constructor for archive + SplineSurface() {} virtual ~SplineSurface() { ; } const auto & GetSplines() const { return splines; } @@ -53,7 +55,11 @@ virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const { return baseprimitive->BoxInSolid(box); } - + + virtual void DoArchive(Archive& ar) + { + ar & geompoints & splines & bcnames & maxh & baseprimitive & cuts & all_cuts; + } /* virtual void Project (Point<3> & p3d) const; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/surface.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/surface.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/surface.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/surface.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -566,4 +566,8 @@ if (Abs2 (rs) < 1e-24 && i > 1) i = 1; } } + +RegisterClassForArchive regsurf; +RegisterClassForArchive regprim; +RegisterClassForArchive regosf; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/surface.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/surface.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/csg/surface.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/csg/surface.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -63,6 +63,12 @@ //@} public: + virtual void DoArchive(Archive& archive) + { + archive & inverse & maxh & name & bcprop & bcname + & p1 & p2 & ex & ey & ez; + } + void SetName (const char * aname); const char * Name () const { return name; } @@ -234,6 +240,9 @@ class Primitive { + protected: + Array surfaceids; + Array surfaceactive; public: @@ -241,6 +250,10 @@ virtual ~Primitive(); + virtual void DoArchive(Archive& archive) + { + archive & surfaceids & surfaceactive; + } /* Check, whether box intersects solid defined by surface. @@ -299,9 +312,6 @@ virtual Surface & GetSurface (int i = 0) = 0; virtual const Surface & GetSurface (int i = 0) const = 0; - Array surfaceids; - Array surfaceactive; - int GetSurfaceId (int i = 0) const; void SetSurfaceId (int i, int id); int SurfaceActive (int i) const { return surfaceactive[i]; } @@ -329,6 +339,12 @@ OneSurfacePrimitive(); ~OneSurfacePrimitive(); + virtual void DoArchive(Archive& archive) + { + Surface::DoArchive(archive); + Primitive::DoArchive(archive); + } + virtual INSOLID_TYPE PointInSolid (const Point<3> & p, double eps) const; virtual INSOLID_TYPE VecInSolid (const Point<3> & p, diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/archive_base.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/archive_base.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/archive_base.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/archive_base.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,144 +0,0 @@ -#ifndef NGS_ARCHIVE_BASE -#define NGS_ARCHIVE_BASE - -// copied from netgen - -#include -#include - -namespace ngstd -{ - - class Archive - { - bool is_output; - public: - Archive (bool ais_output) : is_output(ais_output) { ; } - virtual ~Archive() { ; } - - bool Output () { return is_output; } - bool Input () { return !is_output; } - - virtual Archive & operator & (double & d) = 0; - virtual Archive & operator & (int & i) = 0; - virtual Archive & operator & (long & i) = 0; - virtual Archive & operator & (size_t & i) = 0; - virtual Archive & operator & (short & i) = 0; - virtual Archive & operator & (unsigned char & i) = 0; - virtual Archive & operator & (bool & b) = 0; - virtual Archive & operator & (string & str) = 0; - virtual Archive & operator & (char *& str) = 0; - - template - Archive & Do (T * data, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; - - - virtual Archive & Do (double * d, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; - - virtual Archive & Do (int * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (long * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (size_t * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (short * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (unsigned char * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (bool * b, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; }; - - - // nvirtual Archive & Do (string * str, size_t n) - // { for (size_t j = 0; j < n; j++) { (*this) & str[j]; }; return *this; }; - // virtual Archive & operator & (char *& str) = 0; - - - // archive a pointer ... - - int cnt = 0; - std::map ptr2nr; - std::vector nr2ptr; - - /* - // necessary for msvc ??? - Archive & operator& (string* & ps) - { - return operator& (ps); - } - */ - - template - Archive & operator& (T *& p) - { - if (Output()) - { - if (!p) - { - int m2 = -2; - (*this) & m2; - return *this; - } - auto pos = ptr2nr.find( (void*) p); - if (pos == ptr2nr.end()) - { - ptr2nr[p] = cnt; - int m1 = -1; - (*this) & m1; - cnt++; - (*this) & (*p); - } - else - { - (*this) & pos->second; - } - } - else - { - int nr; - (*this) & nr; - // cout << "in, got nr " << nr << endl; - if (nr == -2) - { - p = nullptr; - } - else if (nr == -1) - { - p = new T; - // cout << "create new ptr, p = " << p << endl; - (*this) & *p; - nr2ptr.push_back(p); - } - else - { - p = (T*)nr2ptr[nr]; - // cout << "reuse ptr " << nr << ": " << p << endl; - } - } - return *this; - } - - - - - template - Archive & operator << (const T & t) - { - T ht(t); - (*this) & ht; - return *this; - } - }; - - -} - - -#endif diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/array.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/array.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/array.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/array.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -400,6 +400,21 @@ ownmem = false; return data; } + + // Only provide this function if T is archivable + template + auto DoArchive(Archive& archive) -> typename std::enable_if, void>::type + { + if(archive.Output()) + archive << size; + else + { + size_t s; + archive & s; + SetSize(s); + } + archive.Do(data, size); + } private: @@ -778,30 +793,6 @@ if(in2.Contains(in1[i]) && in3.Contains(in1[i])) out.Append(in1[i]); } - - - - - template - ngstd::Archive & operator & (ngstd::Archive & archive, Array & a) - { - if (archive.Output()) - archive << a.Size(); - else - { - size_t size; - archive & size; - a.SetSize (size); - } - - /* - for (auto & ai : a) - archive & ai; - */ - archive.Do (&a[BASE], a.Size()); - return archive; - } - } #endif diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -11,7 +11,7 @@ install( FILES ngexception.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel ) install(FILES - archive_base.hpp array.hpp autodiff.hpp autoptr.hpp bitarray.hpp + array.hpp autodiff.hpp autoptr.hpp bitarray.hpp dynamicmem.hpp flags.hpp hashtabl.hpp mpi_interface.hpp myadt.hpp ngsimd.hpp mystring.hpp netgenout.hpp ngexception.hpp ngpython.hpp optmem.hpp parthreads.hpp profiler.hpp seti.hpp sort.hpp diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/hashtabl.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/hashtabl.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/hashtabl.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/hashtabl.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -259,20 +259,13 @@ const T & GetData (const Iterator & it) const { return cont[it.BagNr()][it.Pos()]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { ar & hash & cont; - return ar; } }; - template - inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_2_HASHTABLE & mp) - { return mp.DoArchive(archive); } - - - template inline ostream & operator<< (ostream & ost, const INDEX_2_HASHTABLE & ht) { @@ -436,24 +429,15 @@ { return cont[it.BagNr()][it.Pos()]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { ar & hash & cont; - return ar; } }; - - template - inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_3_HASHTABLE & mp) - { return mp.DoArchive(archive); } - - - - template inline ostream & operator<< (ostream & ost, const INDEX_3_HASHTABLE & ht) { diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/myadt.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/myadt.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/myadt.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/myadt.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -17,11 +17,15 @@ #include "../include/mydefs.hpp" +#include "../core/ngcore.hpp" +namespace netgen +{ + using namespace ngcore; +} #include "ngexception.hpp" #include "parthreads.hpp" // #include "moveablemem.hpp" #include "dynamicmem.hpp" -#include "archive_base.hpp" #include "template.hpp" #include "array.hpp" diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/ngpython.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/ngpython.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/ngpython.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/ngpython.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -1,28 +1,5 @@ #ifdef NG_PYTHON -// BEGIN EVIL HACK: Patch PyThread_get_key_value/PyThread_tss_get inside pybind11 to avoid deadlocks -// see https://github.com/pybind/pybind11/pull/1211 (please merge!) -#if defined(__GNUG__) && !defined(__clang__) -# pragma GCC diagnostic ignored "-Wattributes" -#endif -#include -#include -#include -#undef PYBIND11_TLS_GET_VALUE -#if PY_VERSION_HEX >= 0x03070000 - inline void * PYBIND11_TLS_GET_VALUE(Py_tss_t *state) { - PyThreadState *tstate = (PyThreadState *) PyThread_tss_get(state); - if (!tstate) tstate = PyGILState_GetThisThreadState(); - return tstate; - } -#else - inline void * PYBIND11_TLS_GET_VALUE(int state) { - PyThreadState *tstate = (PyThreadState *) PyThread_get_key_value(state); - if (!tstate) tstate = PyGILState_GetThisThreadState(); - return tstate; - } -#endif -// END EVIL HACK #include #include #include diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/symbolta.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/symbolta.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/symbolta.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/symbolta.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -69,6 +69,8 @@ /// Deletes symboltable inline void DeleteAll (); + void DoArchive(Archive& archive) { archive & names & data;} + inline T & operator[] (int i) { return data[i]; } inline const T & operator[] (int i) const diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/table.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/table.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/table.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/table.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -213,7 +213,7 @@ - ngstd::Archive & BASE_TABLE :: DoArchive (ngstd::Archive & ar, int elemsize) + void BASE_TABLE :: DoArchive (Archive & ar, int elemsize) { if (ar.Output()) { @@ -248,7 +248,6 @@ cnt += data[i].size*elemsize; } } - return ar; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/table.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/table.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/general/table.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/general/table.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -89,7 +89,7 @@ void SetElementSizesToMaxSizes (); - ngstd::Archive & DoArchive (ngstd::Archive & ar, int elemsize); + void DoArchive (Archive & ar, int elemsize); }; @@ -238,21 +238,13 @@ return FlatArray (data[i-BASE].size, (T*)data[i-BASE].col); } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { - return BASE_TABLE::DoArchive(ar, sizeof(T)); + BASE_TABLE::DoArchive(ar, sizeof(T)); } }; - -template - inline ngstd::Archive & operator & (ngstd::Archive & archive, TABLE & mp) - { return mp.DoArchive(archive); } - - - - template inline ostream & operator<< (ostream & ost, const TABLE & table) { diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/genmesh2d.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/genmesh2d.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/genmesh2d.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/genmesh2d.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -207,6 +207,9 @@ // mesh size restrictions ... + + for (auto & point : geompoints) + mesh2d.RestrictLocalH (Point<3> (point(0), point(1), 0), point.hmax); for (int i = 0; i < splines.Size(); i++) { @@ -240,7 +243,21 @@ for (auto mspnt : mp.meshsize_points) mesh2d.RestrictLocalH (mspnt.pnt, mspnt.h); - + + // add point elements + for (auto & point : geompoints) + if (point.name.length()) + { + Point<3> newp(point(0), point(1), 0); + PointIndex npi = mesh2d.AddPoint (newp, 1, FIXEDPOINT); + mesh2d.AddLockedPoint(npi); + Element0d el(npi, npi); + el.name = point.name; + mesh2d.SetCD2Name(npi, point.name); + mesh2d.pointelements.Append (el); + searchtree.Insert (newp, npi); + } + // first add all vertices (for compatible orientation on periodic bnds) { double diam2 = Dist2(pmin, pmax); @@ -584,8 +601,10 @@ // not complete, use at own risk ... // meshing.Delaunay(*mesh, domnr, mp); mp.checkoverlap = 0; - meshing.GenerateMesh (*mesh, mp, h, domnr); - + auto res = meshing.GenerateMesh (*mesh, mp, h, domnr); + if (res != 0) + throw NgException("meshing failed"); + for (SurfaceElementIndex sei = oldnf; sei < mesh->GetNSE(); sei++) (*mesh)[sei].SetIndex (domnr); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/geom2dmesh.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/geom2dmesh.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/geom2dmesh.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/geom2dmesh.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -47,8 +47,8 @@ auto ext = dynamic_cast(spline); if(ext) { - ss3 = dynamic_cast *>(&ext->seg); - ls = dynamic_cast *>(&ext->seg); + ss3 = dynamic_cast *>(ext->seg); + ls = dynamic_cast *>(ext->seg); } else { diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/geometry2d.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/geometry2d.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/geometry2d.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/geometry2d.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -1034,5 +1034,6 @@ }; SplineGeoInit sginit; - + static RegisterClassForArchive, NetgenGeometry> regspg2; + static RegisterClassForArchive> regssext; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/geometry2d.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/geometry2d.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/geometry2d.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/geometry2d.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -21,7 +21,7 @@ class SplineSegExt : public SplineSeg<2> { public: - const SplineSeg<2> & seg; + SplineSeg<2>* seg; /// left domain int leftdom; @@ -42,35 +42,43 @@ /// int layer; - SplineSegExt (const SplineSeg<2> & hseg) - : seg(hseg) + SplineSegExt (SplineSeg<2> & hseg) + : seg(&hseg) { layer = 1; } + // default constructor for archive + SplineSegExt() {} ~SplineSegExt () { - delete &seg; + delete seg; + } + + virtual void DoArchive(Archive& ar) + { + ar & seg & leftdom & rightdom & reffak & hmax & bc & copyfrom + & hpref_left & hpref_right & layer; } virtual const GeomPoint<2> & StartPI () const { - return seg.StartPI(); + return seg->StartPI(); } virtual const GeomPoint<2> & EndPI () const { - return seg.EndPI(); + return seg->EndPI(); } virtual Point<2> GetPoint (double t) const { - return seg.GetPoint(t); + return seg->GetPoint(t); } virtual Vec<2> GetTangent (const double t) const { - return seg.GetTangent(t); + return seg->GetTangent(t); } virtual void GetDerivatives (const double t, @@ -78,27 +86,27 @@ Vec<2> & first, Vec<2> & second) const { - seg.GetDerivatives (t, point, first, second); + seg->GetDerivatives (t, point, first, second); } virtual void GetCoeff (Vector & coeffs) const { - seg.GetCoeff (coeffs); + seg->GetCoeff (coeffs); } virtual void GetPoints (int n, Array > & points) const { - seg.GetPoints (n, points); + seg->GetPoints (n, points); } virtual double MaxCurvature () const { - return seg.MaxCurvature(); + return seg->MaxCurvature(); } virtual string GetType () const { - return seg.GetType(); + return seg->GetType(); } virtual double CalcCurvature (double t) const @@ -112,7 +120,7 @@ virtual bool InConvexHull (Point<2> p, double eps) const { - return seg.InConvexHull (p, eps); + return seg->InConvexHull (p, eps); } }; @@ -143,7 +151,11 @@ void TestComment ( ifstream & infile ) ; - + void DoArchive(Archive& ar) + { + SplineGeometry<2>::DoArchive(ar); + ar & materials & maxh & quadmeshing & tensormeshing & layer & bcnames & elto0; + } const SplineSegExt & GetSpline (const int i) const { diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/python_geom2d.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/python_geom2d.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/geom2d/python_geom2d.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/geom2d/python_geom2d.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -19,19 +19,34 @@ (m, "SplineGeometry", "a 2d boundary representation geometry model by lines and splines") .def(py::init<>()) - .def("__init__", - [](SplineGeometry2d *instance, const string & filename) - { - cout << "load geometry"; - ifstream ist(filename); - new (instance) SplineGeometry2d(); - instance->Load (filename.c_str()); - ng_geometry = shared_ptr(instance, NOOP_Deleter); - }) + .def(py::init([](const string& filename) + { + auto geo = make_shared(); + geo->Load(filename.c_str()); + ng_geometry = geo; + return geo; + })) + .def(py::pickle( + [](SplineGeometry2d& self) + { + auto ss = make_shared(); + BinaryOutArchive archive(ss); + archive & self; + archive.FlushBuffer(); + return py::make_tuple(py::bytes(ss->str())); + }, + [](py::tuple state) + { + auto geo = make_shared(); + auto ss = make_shared (py::cast(state[0])); + BinaryInArchive archive(ss); + archive & (*geo); + return geo; + })) .def("Load",&SplineGeometry2d::Load) .def("AppendPoint", FunctionPointer - ([](SplineGeometry2d &self, double px, double py, double maxh, double hpref) + ([](SplineGeometry2d &self, double px, double py, double maxh, double hpref, string name) { Point<2> p; p(0) = px; @@ -39,10 +54,11 @@ GeomPoint<2> gp(p); gp.hmax = maxh; gp.hpref = hpref; + gp.name = name; self.geompoints.Append(gp); return self.geompoints.Size()-1; }), - py::arg("x"), py::arg("y"), py::arg("maxh") = 1e99, py::arg("hpref")=0) + py::arg("x"), py::arg("y"), py::arg("maxh") = 1e99, py::arg("hpref")=0, py::arg("name")="") .def("Append", FunctionPointer([](SplineGeometry2d &self, py::list segment, int leftdomain, int rightdomain, py::object bc, py::object copy, double maxh, double hpref) { diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/geomobjects.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/geomobjects.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/geomobjects.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/geomobjects.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -64,6 +64,12 @@ const T & operator() (int i) const { return x[i]; } operator const T* () const { return x; } + + void DoArchive(Archive& archive) + { + for(int i=0; i @@ -117,6 +123,12 @@ operator const T* () const { return x; } + void DoArchive(Archive& archive) + { + for(int i=0; i - inline Point SplineSeg3 :: GetPoint (double t) const + Point SplineSeg3 :: GetPoint (double t) const { double b1, b2, b3; @@ -551,11 +551,10 @@ template class SplineSeg3<2>; template class SplineSeg3<3>; - - - - - - - + RegisterClassForArchive> regss2; + RegisterClassForArchive> regss3; + RegisterClassForArchive, SplineSeg<2>> regls2; + RegisterClassForArchive, SplineSeg<3>> regls3; + RegisterClassForArchive, SplineSeg<2>> regsss2; + RegisterClassForArchive, SplineSeg<3>> regsss3; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/splinegeometry.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/splinegeometry.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/splinegeometry.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/splinegeometry.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -129,6 +129,8 @@ template class SplineGeometry<2>; template class SplineGeometry<3>; + static RegisterClassForArchive> regsp2; + static RegisterClassForArchive> regsp3; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/splinegeometry.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/splinegeometry.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/splinegeometry.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/splinegeometry.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -34,6 +34,11 @@ DLL_HEADER int Load (const Array & raw_data, const int startpos = 0); + virtual void DoArchive(Archive& ar) + { + ar & geompoints & splines; + } + DLL_HEADER void GetRawData (Array & raw_data) const; @@ -55,7 +60,6 @@ // void SetGrading (const double grading); DLL_HEADER void AppendPoint (const Point & p, const double reffac = 1., const bool hpref = false); - void AppendSegment(SplineSeg * spline) { splines.Append (spline); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/spline.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/spline.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/gprim/spline.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/gprim/spline.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -28,13 +28,19 @@ double hmax; /// hp-refinement double hpref; - + /// + string name; /// GeomPoint () { ; } /// GeomPoint (const Point & ap, double aref = 1, double ahpref=0) : Point(ap), refatpoint(aref), hmax(1e99), hpref(ahpref) { ; } + void DoArchive(Archive& ar) + { + Point::DoArchive(ar); + ar & refatpoint & hmax & hpref; + } }; @@ -72,6 +78,7 @@ second = 1.0/sqr(eps) * ( (pr-point)+(pl-point)); } + virtual void DoArchive(Archive& ar) = 0; /// returns initial point on curve virtual const GeomPoint & StartPI () const = 0; @@ -122,6 +129,12 @@ /// LineSeg (const GeomPoint & ap1, const GeomPoint & ap2); /// + // default constructor for archive + LineSeg() {} + virtual void DoArchive(Archive& ar) + { + ar & p1 & p2; + } virtual double Length () const; /// inline virtual Point GetPoint (double t) const; @@ -172,8 +185,14 @@ SplineSeg3 (const GeomPoint & ap1, const GeomPoint & ap2, const GeomPoint & ap3); + // default constructor for archive + SplineSeg3() {} /// - inline virtual Point GetPoint (double t) const; + virtual void DoArchive(Archive& ar) + { + ar & p1 & p2 & p3 & weight & proj_latest_t; + } + virtual Point GetPoint (double t) const; /// virtual Vec GetTangent (const double t) const; @@ -226,6 +245,12 @@ CircleSeg (const GeomPoint & ap1, const GeomPoint & ap2, const GeomPoint & ap3); + // default constructor for archive + CircleSeg() {} + virtual void DoArchive(Archive& ar) + { + ar & p1 & p2 & p3 & pm & radius & w1 & w3; + } /// virtual Point GetPoint (double t) const; /// @@ -270,6 +295,12 @@ public: /// DiscretePointsSeg (const Array > & apts); + // default constructor for archive + DiscretePointsSeg() {} + virtual void DoArchive(Archive& ar) + { + ar & pts & p1n & p2n; + } /// virtual ~DiscretePointsSeg (); /// @@ -624,8 +655,14 @@ /// BSplineSeg (const Array > & apts); /// + //default constructor for archive + BSplineSeg() {} virtual ~BSplineSeg(); /// + virtual void DoArchive(Archive& ar) + { + ar & pts & p1n & p2n & ti; + } virtual Point GetPoint (double t) const; /// virtual const GeomPoint & StartPI () const { return p1n; }; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/include/nginterface_v2.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/include/nginterface_v2.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/include/nginterface_v2.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/include/nginterface_v2.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -230,7 +230,7 @@ void LoadMesh (istream & str); void SaveMesh (ostream & str) const; void UpdateTopology (); - void DoArchive (ngstd::Archive & archive); + void DoArchive (Archive & archive); virtual ~Ngx_Mesh(); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/include/nginterface_v2_impl.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/include/nginterface_v2_impl.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/include/nginterface_v2_impl.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/include/nginterface_v2_impl.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -47,6 +47,7 @@ Ng_Element ret; ret.type = NG_PNT; ret.index = el.index; + ret.mat = &el.name; ret.points.num = 1; ret.points.ptr = (int*)&el.pnum; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/interface/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/libsrc/interface/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/interface/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/interface/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -9,9 +9,7 @@ if(NOT WIN32) target_link_libraries(interface mesh csg geom2d) - if(USE_GUI) - target_link_libraries(interface visual) - endif(USE_GUI) + target_link_libraries(interface visual) install( TARGETS interface ${NG_INSTALL_DIR}) endif(NOT WIN32) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/interface/nginterface_v2.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/interface/nginterface_v2.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/interface/nginterface_v2.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/interface/nginterface_v2.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -69,7 +69,7 @@ mesh -> Save (ost); } - void Ngx_Mesh :: DoArchive (ngstd::Archive & archive) + void Ngx_Mesh :: DoArchive (Archive & archive) { if (archive.Input()) mesh = make_shared(); mesh->DoArchive(archive); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/linalg/vector.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/linalg/vector.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/linalg/vector.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/linalg/vector.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -139,6 +139,14 @@ ~Vector () { if (ownmem) delete [] data; } + virtual void DoArchive(Archive& ar) + { + auto size = s; + ar & ownmem & size; + if(!ar.Output()) + SetSize(size); + ar.Do(data, size); + } Vector & operator= (const FlatVector & v) { memcpy (data, &v(0), s*sizeof(double)); return *this; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/adfront2.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/adfront2.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/adfront2.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/adfront2.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -22,7 +22,7 @@ mgi = new MultiPointGeomInfo (*amgi); for (int i = 1; i <= mgi->GetNPGI(); i++) if (mgi->GetPGI(i).trignum <= 0) - cout << "Add FrontPoint2, illegal geominfo = " << mgi->GetPGI(i).trignum << endl; + cout << "WARNING: Add FrontPoint2, illegal geominfo = " << mgi->GetPGI(i).trignum << endl; } else mgi = NULL; @@ -136,7 +136,7 @@ if (!gi1.trignum || !gi2.trignum) { - cout << "ERROR: in AdFront::AddLine, illegal geominfo" << endl; + cout << "WARNING: in AdFront::AddLine, illegal geominfo" << endl; } lines[li].SetGeomInfo (gi1, gi2); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/basegeom.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/basegeom.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/basegeom.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/basegeom.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -74,4 +74,5 @@ throw NgException("Cannot save geometry - no geometry available"); } + static RegisterClassForArchive regnggeo; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/basegeom.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/basegeom.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/basegeom.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/basegeom.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -22,6 +22,9 @@ virtual const Refinement & GetRefinement () const; + virtual void DoArchive(Archive&) + { throw NgException("DoArchive not implemented for " + Demangle(typeid(*this).name())); } + virtual void Save (string filename) const; virtual void SaveToMeshFile (ostream & /* ost */) const { ; } }; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -30,7 +30,7 @@ endif(APPLE) if(NOT WIN32) - target_link_libraries( mesh ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY}) + target_link_libraries( mesh ngcore ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY}) install( TARGETS mesh ${NG_INSTALL_DIR}) endif(NOT WIN32) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/curvedelems.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/curvedelems.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/curvedelems.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/curvedelems.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -48,6 +48,11 @@ int GetOrder () { return order; } + virtual void DoArchive(Archive& ar) + { + ar & edgeorder & faceorder & edgecoeffsindex & facecoeffsindex & edgecoeffs & facecoeffs + & edgeweight & order & rational & ishighorder; + } bool IsSegmentCurved (SegmentIndex segnr) const; bool IsSurfaceElementCurved (SurfaceElementIndex sei) const; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshclass.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshclass.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshclass.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshclass.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -1304,7 +1304,7 @@ } - void Mesh :: DoArchive (ngstd::Archive & archive) + void Mesh :: DoArchive (Archive & archive) { archive & dimension; archive & points; @@ -1316,22 +1316,8 @@ archive & *ident; - - // archive geometry - if (archive.Output()) - { - ostringstream ost; - if (geometry) - geometry -> SaveToMeshFile (ost); - archive << ost.str(); - } - else - { - string str; - archive & str; - istringstream ist(str); - geometry = geometryregister.LoadFromMeshFile (ist); - } + archive & geometry; + archive & *curvedelems; if (archive.Input()) { diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshclass.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshclass.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshclass.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshclass.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -517,7 +517,7 @@ DLL_HEADER void Merge (const string & filename, const int surfindex_offset = 0); - DLL_HEADER void DoArchive (ngstd::Archive & archive); + DLL_HEADER void DoArchive (Archive & archive); /// DLL_HEADER void ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal = OPT_QUALITY); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshtype.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshtype.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshtype.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshtype.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -148,9 +148,9 @@ return *this; } - ngstd::Archive & Segment :: DoArchive (ngstd::Archive & ar) + void Segment :: DoArchive (Archive & ar) { - return ar & pnums[0] & pnums[1] & pnums[2] + ar & pnums[0] & pnums[1] & pnums[2] & edgenr & singedge_left & singedge_right & si & cd2i & domin & domout & tlosurf & surfnr1 & surfnr2 @@ -2427,9 +2427,9 @@ bcn = &default_bcname; } - ngstd::Archive & FaceDescriptor :: DoArchive (ngstd::Archive & ar) + void FaceDescriptor :: DoArchive (Archive & ar) { - return ar & surfnr & domin & domout & tlosurf & bcprop + ar & surfnr & domin & domout & tlosurf & bcprop & surfcolour.X() & surfcolour.Y() & surfcolour.Z() & bcname & domin_singular & domout_singular ; @@ -2482,7 +2482,7 @@ maxidentnr = 0; } - ngstd::Archive & Identifications :: DoArchive (ngstd::Archive & ar) + void Identifications :: DoArchive (Archive & ar) { ar & maxidentnr; ar & identifiedpoints & identifiedpoints_nr; @@ -2503,7 +2503,6 @@ for (auto & t : type) ar & (unsigned char&)(t); } - return ar; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshtype.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshtype.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/meshtype.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/meshtype.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -171,13 +171,9 @@ enum { BASE = 1 }; #endif - ngstd::Archive & DoArchive (ngstd::Archive & ar) { return ar & i; } + void DoArchive (Archive & ar) { ar & i; } }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, PointIndex & mp) - { return mp.DoArchive(archive); } - - inline istream & operator>> (istream & ist, PointIndex & pi) { int i; ist >> i; pi = PointIndex(i); return ist; @@ -247,14 +243,9 @@ SurfaceElementIndex & operator-- () { --i; return *this; } SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) { return ar & i; } + void DoArchive (Archive & ar) { ar & i; } }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, SurfaceElementIndex & mp) - { return mp.DoArchive(archive); } - - - inline istream & operator>> (istream & ist, SurfaceElementIndex & pi) { int i; ist >> i; pi = i; return ist; @@ -337,19 +328,13 @@ static MPI_Datatype MyGetMPIType ( ); #endif - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { ar & x[0] & x[1] & x[2] & layer & singular; ar & (unsigned char&)(type); - return ar; } }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, MeshPoint & mp) - { return mp.DoArchive(archive); } - - - inline ostream & operator<<(ostream & s, const MeshPoint & pt) { return (s << Point<3> (pt)); @@ -497,7 +482,7 @@ /// const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { short _np, _typ; bool _curved, _vis, _deleted; @@ -511,7 +496,6 @@ visible = _vis; deleted = _deleted; } for (size_t i = 0; i < np; i++) ar & pnum[i]; - return ar; } void SetIndex (int si) { index = si; } @@ -630,9 +614,6 @@ #endif }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, Element2d & mp) - { return mp.DoArchive(archive); } - ostream & operator<<(ostream & s, const Element2d & el); @@ -774,7 +755,7 @@ /// const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { short _np, _typ; if (ar.Output()) @@ -784,7 +765,6 @@ { np = _np; typ = ELEMENT_TYPE(_typ); } for (size_t i = 0; i < np; i++) ar & pnum[i]; - return ar; } /// @@ -928,9 +908,6 @@ int hp_elnr; }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, Element & mp) - { return mp.DoArchive(archive); } - ostream & operator<<(ostream & s, const Element & el); @@ -1049,12 +1026,9 @@ #else int GetPartition () const { return 0; } #endif - ngstd::Archive & DoArchive (ngstd::Archive & ar); + void DoArchive (Archive & ar); }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, Segment & mp) - { return mp.DoArchive(archive); } - ostream & operator<<(ostream & s, const Segment & seg); @@ -1062,6 +1036,7 @@ { public: PointIndex pnum; + string name; int index; Element0d () = default; Element0d (PointIndex _pnum, int _index) @@ -1142,13 +1117,9 @@ // friend ostream & operator<<(ostream & s, const FaceDescriptor & fd); friend class Mesh; - ngstd::Archive & DoArchive (ngstd::Archive & ar); + void DoArchive (Archive & ar); }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, FaceDescriptor & mp) - { return mp.DoArchive(archive); } - - ostream & operator<< (ostream & s, const FaceDescriptor & fd); @@ -1516,12 +1487,8 @@ DLL_HEADER void Print (ostream & ost) const; - ngstd::Archive & DoArchive (ngstd::Archive & ar); + void DoArchive (Archive & ar); }; - - inline ngstd::Archive & operator & (ngstd::Archive & archive, Identifications & mp) - { return mp.DoArchive(archive); } - } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/python_mesh.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/python_mesh.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/meshing/python_mesh.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/meshing/python_mesh.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -488,7 +488,7 @@ auto mesh = make_shared(); mesh -> SetDimension(dim); SetGlobalMesh(mesh); // for visualization - mesh -> SetGeometry (make_shared()); + mesh -> SetGeometry (nullptr); return mesh; } ), py::arg("dim")=3 @@ -565,8 +565,6 @@ break; } } - if (!ng_geometry) - ng_geometry = make_shared(); self.SetGeometry(ng_geometry); delete infile; }),py::call_guard()) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -4,13 +4,17 @@ Partition_Loop.cxx Partition_Loop2d.cxx Partition_Loop3d.cxx Partition_Spliter.cxx occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp python_occ.cpp ) - -add_library(occvis ${NG_LIB_TYPE} vsocc.cpp) +if(USE_GUI) + add_library(occvis ${NG_LIB_TYPE} vsocc.cpp) +endif(USE_GUI) if(NOT WIN32) target_link_libraries( occ ${OCC_LIBRARIES} ${PYTHON_LIBRARIES}) - target_link_libraries( occvis occ ) - install( TARGETS occ occvis ${NG_INSTALL_DIR}) + install( TARGETS occ ${NG_INSTALL_DIR}) + if (USE_GUI) + target_link_libraries( occvis occ ) + install( TARGETS occvis ${NG_INSTALL_DIR}) + endif(USE_GUI) endif(NOT WIN32) install(FILES diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/occgeom.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/occgeom.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/occgeom.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/occgeom.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -3,6 +3,7 @@ #include #include +#include #include "ShapeAnalysis_ShapeTolerance.hxx" #include "ShapeAnalysis_ShapeContents.hxx" #include "ShapeAnalysis_CheckSmallFace.hxx" @@ -1106,94 +1107,8 @@ // } - - // Philippose - 23/02/2009 - /* Special IGES File load function including the ability - to extract individual surface colours via the extended - OpenCascade XDE and XCAF Feature set. - */ - OCCGeometry *LoadOCC_IGES(const char *filename) - { - OCCGeometry *occgeo; - occgeo = new OCCGeometry; - - // Initiate a dummy XCAF Application to handle the IGES XCAF Document - static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); - - // Create an XCAF Document to contain the IGES file itself - Handle_TDocStd_Document iges_doc; - - // Check if a IGES File is already open under this handle, if so, close it to prevent - // Segmentation Faults when trying to create a new document - if(dummy_app->NbDocuments() > 0) - { - dummy_app->GetDocument(1,iges_doc); - dummy_app->Close(iges_doc); - } - dummy_app->NewDocument ("IGES-XCAF",iges_doc); - - IGESCAFControl_Reader reader; - - Standard_Integer stat = reader.ReadFile((char*)filename); - - if(stat != IFSelect_RetDone) - { - delete occgeo; - return NULL; - } - - // Enable transfer of colours - reader.SetColorMode(Standard_True); - - reader.Transfer(iges_doc); - - // Read in the shape(s) and the colours present in the IGES File - Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main()); - Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main()); - - TDF_LabelSequence iges_shapes; - iges_shape_contents->GetShapes(iges_shapes); - - // List out the available colours in the IGES File as Colour Names - TDF_LabelSequence all_colours; - iges_colour_contents->GetColors(all_colours); - PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length()); - for(int i = 1; i <= all_colours.Length(); i++) - { - Quantity_Color col; - stringstream col_rgb; - iges_colour_contents->GetColor(all_colours.Value(i),col); - col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; - PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str()); - } - - - // For the IGES Reader, all the shapes can be exported as one compound shape - // using the "OneShape" member - occgeo->shape = reader.OneShape(); - occgeo->face_colours = iges_colour_contents; - occgeo->changed = 1; - occgeo->BuildFMap(); - - occgeo->CalcBoundingBox(); - PrintContents (occgeo); - - return occgeo; - } - - - - - - // Philippose - 29/01/2009 - /* Special STEP File load function including the ability - to extract individual surface colours via the extended - OpenCascade XDE and XCAF Feature set. - */ - OCCGeometry * LoadOCC_STEP (const char * filename) - { - OCCGeometry * occgeo; - occgeo = new OCCGeometry; + void LoadOCCInto(OCCGeometry* occgeo, const char* filename) + { // Initiate a dummy XCAF Application to handle the STEP XCAF Document static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); @@ -1219,8 +1134,7 @@ if(stat != IFSelect_RetDone) { - delete occgeo; - return NULL; + throw NgException("Couldn't load OCC geometry"); } reader.Transfer(step_doc); @@ -1287,6 +1201,94 @@ // cout << occgeo->enames[i] << endl; // cout << " " <NbDocuments() > 0) + { + dummy_app->GetDocument(1,iges_doc); + dummy_app->Close(iges_doc); + } + dummy_app->NewDocument ("IGES-XCAF",iges_doc); + + IGESCAFControl_Reader reader; + + Standard_Integer stat = reader.ReadFile((char*)filename); + + if(stat != IFSelect_RetDone) + { + throw NgException("Couldn't load occ"); + } + + // Enable transfer of colours + reader.SetColorMode(Standard_True); + + reader.Transfer(iges_doc); + + // Read in the shape(s) and the colours present in the IGES File + Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main()); + Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main()); + + TDF_LabelSequence iges_shapes; + iges_shape_contents->GetShapes(iges_shapes); + + // List out the available colours in the IGES File as Colour Names + TDF_LabelSequence all_colours; + iges_colour_contents->GetColors(all_colours); + PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length()); + for(int i = 1; i <= all_colours.Length(); i++) + { + Quantity_Color col; + stringstream col_rgb; + iges_colour_contents->GetColor(all_colours.Value(i),col); + col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; + PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str()); + } + + + // For the IGES Reader, all the shapes can be exported as one compound shape + // using the "OneShape" member + occgeo->shape = reader.OneShape(); + occgeo->face_colours = iges_colour_contents; + occgeo->changed = 1; + occgeo->BuildFMap(); + + occgeo->CalcBoundingBox(); + PrintContents (occgeo); + return occgeo; + } + + + + + + // Philippose - 29/01/2009 + /* Special STEP File load function including the ability + to extract individual surface colours via the extended + OpenCascade XDE and XCAF Feature set. + */ + OCCGeometry * LoadOCC_STEP (const char * filename) + { + OCCGeometry * occgeo; + occgeo = new OCCGeometry; + + LoadOCCInto(occgeo, filename); return occgeo; } @@ -1355,8 +1357,34 @@ } } - - + void OCCGeometry :: DoArchive(Archive& ar) + { + if(ar.Output()) + { + std::stringstream ss; + STEPControl_Writer writer; + writer.Transfer(shape, STEPControl_AsIs); + auto filename = ".tmpfile_out.step"; + writer.Write(filename); + std::ifstream is(filename); + ss << is.rdbuf(); + ar << ss.str(); + std::remove(filename); + } + else + { + std::string str; + ar & str; + + auto filename = ".tmpfile.step"; + auto tmpfile = std::fopen(filename, "w"); + std::fputs(str.c_str(), tmpfile); + std::fclose(tmpfile); + LoadOCCInto(this, filename); + std::remove(filename); + } + } + const char * shapesname[] = {" ", "CompSolids", "Solids", "Shells", diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/occgeom.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/occgeom.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/occgeom.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/occgeom.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -246,6 +246,7 @@ DLL_HEADER virtual void Save (string filename) const; + void DoArchive(Archive& ar); DLL_HEADER void BuildFMap(); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/python_occ.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/python_occ.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/occ/python_occ.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/occ/python_occ.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -18,6 +18,23 @@ { py::class_, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string") .def(py::init<>()) + .def(py::pickle( + [](OCCGeometry& self) + { + auto ss = make_shared(); + BinaryOutArchive archive(ss); + archive & self; + archive.FlushBuffer(); + return py::make_tuple(py::bytes(ss->str())); + }, + [](py::tuple state) + { + auto geo = make_shared(); + auto ss = make_shared (py::cast(state[0])); + BinaryInArchive archive(ss); + archive & (*geo); + return geo; + })) .def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions) { self.tolerance = tolerance; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/python_stl.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/python_stl.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/python_stl.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/python_stl.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -20,6 +20,23 @@ { py::class_, NetgenGeometry> (m,"STLGeometry") .def(py::init<>()) + .def(py::pickle( + [](STLGeometry& self) + { + auto ss = make_shared(); + BinaryOutArchive archive(ss); + archive & self; + archive.FlushBuffer(); + return py::make_tuple(py::bytes(ss->str())); + }, + [](py::tuple state) + { + auto geo = make_shared(); + auto ss = make_shared (py::cast(state[0])); + BinaryInArchive archive(ss); + archive & (*geo); + return geo; + })) .def("_visualizationData", [](shared_ptr stl_geo) { std::vector vertices; diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stlgeom.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stlgeom.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stlgeom.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stlgeom.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -3579,5 +3579,5 @@ STLInit stlinit; - +static RegisterClassForArchive stlgeo; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stlgeom.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stlgeom.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stlgeom.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stlgeom.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -184,6 +184,10 @@ STLGeometry(); virtual ~STLGeometry(); + void DoArchive(Archive& ar) + { + STLTopology::DoArchive(ar); + } void Clear(); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stltopology.cpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stltopology.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stltopology.cpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stltopology.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -1074,5 +1074,5 @@ } } - +static RegisterClassForArchive stltop; } diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stltopology.hpp ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stltopology.hpp --- ngsolve-6.2.1810/external_dependencies/netgen/libsrc/stlgeom/stltopology.hpp 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/libsrc/stlgeom/stltopology.hpp 2019-01-12 00:19:01.000000000 +0000 @@ -96,6 +96,17 @@ STLTriangle (const int * apts); STLTriangle () {pts[0]=0;pts[1]=0;pts[2]=0;} + void DoArchive(Archive& ar) + { + ar.Do(&topedges[0],3); + ar.Do(&nbtrigs[0][0], 6); + ar.Do(&pts[0],3); + ar.Do(&domains[0],2); + size_t i = flags.toperror; + ar & normal & box & center & rad & facenum & i; + flags.toperror = i; + } + int operator[] (int i) const { return pts[i]; } int & operator[] (int i) { return pts[i]; } @@ -279,6 +290,13 @@ void Save (const char* filename) const; void SaveBinary (const char* filename, const char* aname) const; void SaveSTLE (const char * filename) const; // stores trigs and edges + + virtual void DoArchive(Archive& ar) + { + ar & trias & points & boundingbox & pointtol; + if(ar.Input()) + FindNeighbourTrigs(); + } virtual void InitSTLGeometry (const Array & readtrigs); diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/nglib/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/nglib/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/nglib/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/nglib/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -32,6 +32,8 @@ endif(USE_GUI) endif(NOT WIN32) +target_link_libraries(nglib PUBLIC ngcore) + target_link_libraries( nglib PRIVATE ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} ) if(USE_OCC AND NOT WIN32) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/build_guidelines.sh ngsolve-6.2.1901/external_dependencies/netgen/tests/build_guidelines.sh --- ngsolve-6.2.1810/external_dependencies/netgen/tests/build_guidelines.sh 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/build_guidelines.sh 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,8 @@ +cd +mkdir -p build/netgen +cd build/netgen +cmake ../../src/netgen -DUSE_CCACHE=ON -DENABLE_CPP_CORE_GUIDELINES_CHECK=ON -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_C_COMPILER=clang +make -j12 +make install + diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/archive.cpp ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/archive.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/archive.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/archive.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,317 @@ + +#include "catch.hpp" +#include <../core/ngcore.hpp> +using namespace ngcore; +using namespace std; + +class CommonBase +{ +public: + int a; + virtual ~CommonBase() {} + + virtual void DoArchive(Archive& archive) { archive & a; } +}; + +// pure abstract base class +class SharedPtrHolder : virtual public CommonBase +{ +public: + vector> names; + virtual ~SharedPtrHolder() + { } + + virtual void abstract() = 0; + virtual void DoArchive(Archive& archive) + { + CommonBase::DoArchive(archive); + archive & names; + } +}; + +class PtrHolder : virtual public CommonBase +{ +public: + vector numbers; + virtual ~PtrHolder() {} + + virtual void DoArchive(Archive& archive) + { + CommonBase::DoArchive(archive); + archive & numbers; + } +}; + +class SharedPtrAndPtrHolder : public SharedPtrHolder, public PtrHolder +{ +public: + virtual ~SharedPtrAndPtrHolder() {} + virtual void DoArchive(Archive& archive) + { + SharedPtrHolder::DoArchive(archive); + PtrHolder::DoArchive(archive); + } + virtual void abstract() {} +}; + +// Classes without virt. or multiple inheritance do not need to be registered +class SimpleClass : public CommonBase +{ +public: + double d; + virtual void DoArchive(Archive& ar) + { + CommonBase::DoArchive(ar); + ar & d; + } +}; + +class NotRegisteredForArchive : public SharedPtrAndPtrHolder {}; + +class ClassWithConstPtr +{ +private: + const int* ptr; +public: + ClassWithConstPtr(const int* aptr) : ptr(aptr) { } + // constructor only for archive + ClassWithConstPtr() {} + void DoArchive(Archive& ar) + { + ar & ptr; + } + const int* getPtr() { return ptr; } +}; + +class OneMoreDerivedClass : public SharedPtrAndPtrHolder {}; + +static RegisterClassForArchive regb; +static RegisterClassForArchive regsp; +static RegisterClassForArchive regp; +static RegisterClassForArchive regspp; +static RegisterClassForArchive regom; + +void testNullPtr(Archive& in, Archive& out) +{ + SharedPtrHolder* p = nullptr; + shared_ptr sp = nullptr; + out & p & sp; + out.FlushBuffer(); + SharedPtrHolder* pin = nullptr; + shared_ptr spin = nullptr; + in & pin & spin; + CHECK(pin == nullptr); + CHECK(spin == nullptr); +} + +void testSharedPointer(Archive& in, Archive& out) +{ + SECTION("Same shared ptr") + { + static_assert(detail::has_DoArchive::value, ""); + SharedPtrAndPtrHolder holder, holder2; + holder.names.push_back(make_shared("name")); + holder2.names = holder.names; // same shared ptr + out & holder & holder2; + out.FlushBuffer(); + SharedPtrAndPtrHolder inholder, inholder2; + in & inholder & inholder2; + CHECK(inholder.names.size() == 1); + CHECK(inholder.names[0] == inholder2.names[0]); + CHECK(inholder.names[0].use_count() == 3); // one shared ptr is still kept in the archive + CHECK(*inholder.names[0] == "name"); + } +} + +void testPointer(Archive& in, Archive& out) +{ + PtrHolder holder, holder2; + holder.numbers.push_back(new int(3)); + holder2.numbers = holder.numbers; // same shared ptr + out & holder & holder2; + out.FlushBuffer(); + PtrHolder inholder, inholder2; + in & inholder & inholder2; + CHECK(inholder.numbers.size() == 1); + CHECK(inholder.numbers[0] == inholder2.numbers[0]); + CHECK(*inholder.numbers[0] == 3); +} + +void testConstPointer(Archive& in, Archive& out) +{ + SECTION("Const pointer") + { + int* iptr = new int(4); + double d = 0.1; + ClassWithConstPtr cls(iptr); + out & cls & iptr & d; + out.FlushBuffer(); + ClassWithConstPtr incls; + int* iniptr; + double ind; + in & incls & iniptr & ind; + CHECK(*incls.getPtr() == 4); + CHECK(incls.getPtr() == iniptr); + CHECK(ind == 0.1); + delete iptr; + delete iniptr; + } +} + +void testMultipleInheritance(Archive& in, Archive& out) +{ + PtrHolder* p = new OneMoreDerivedClass; + p->numbers.push_back(new int(2)); + p->a = 5; + auto p2 = dynamic_cast(p); + p2->names.push_back(make_shared("test")); + auto sp1 = shared_ptr(p); + auto sp2 = dynamic_pointer_cast(sp1); + auto checkPtr = [] (auto pin, auto pin2) + { + CHECK(typeid(*pin) == typeid(*pin2)); + CHECK(typeid(*pin) == typeid(OneMoreDerivedClass)); + CHECK(*pin2->names[0] == "test"); + CHECK(*pin->numbers[0] == 2); + CHECK(dynamic_cast(pin) == dynamic_cast(pin2)); + CHECK(pin->a == pin2->a); + CHECK(pin->a == 5); + REQUIRE(dynamic_cast(pin2) != nullptr); + CHECK(*dynamic_cast(pin2)->numbers[0] == 2); + CHECK(*pin->numbers[0] == *dynamic_cast(pin2)->numbers[0]); + REQUIRE(dynamic_cast(pin) != nullptr); + CHECK(dynamic_cast(pin)->names[0] == pin2->names[0]); + }; + SECTION("Archive ptrs to leaves of mult. inh.") + { + out & p & p2; + out.FlushBuffer(); + PtrHolder* pin = nullptr; + SharedPtrHolder* pin2 = nullptr; + in & pin & pin2; + checkPtr(pin, pin2); + } + SECTION("Archive shared ptrs to leaves of mult. inh.") + { + out & sp1 & sp2; + out.FlushBuffer(); + shared_ptr pin; + shared_ptr pin2; + in & pin & pin2; + checkPtr(pin.get(), pin2.get()); + } + SECTION("Virtual base class") + { + CommonBase* b = dynamic_cast(p); + out & b & p; + PtrHolder* pin; + CommonBase* bin; + in & bin & pin; + checkPtr(pin, dynamic_cast(bin)); + } + SECTION("Simple class without register") + { + auto a = new SimpleClass; + a->a = 5; + a->d = 2.3; + SECTION("check pointer") + { + out & a; + out.FlushBuffer(); + SimpleClass* ain; + in & ain; + CHECK(ain->a == 5); + CHECK(ain->d == 2.3); + } + SECTION("check shared pointer") + { + auto spa = shared_ptr(a); + out & spa; + out.FlushBuffer(); + shared_ptr spain; + in & spain; + CHECK(spain->a == 5); + CHECK(spain->d == 2.3); + } + } +} + +void testLibraryVersion(Archive& in, Archive& out) +{ + SetLibraryVersion("netgen","v6.2.1812"); + CHECK(in.GetVersion("netgen") == "v6.2.1811"); + CHECK(out.GetVersion("netgen") == "v6.2.1812"); +} + +void testArchive(Archive& in, Archive& out) +{ + SECTION("Empty String") + { + char* cstr = nullptr; + char* empty = new char[1]; + char* simple = new char[7] {'s','i','m','p','l','e','\0'}; + empty[0] = '\0'; + out << string("") << cstr << empty << simple << string("simple") << long(1); + out.FlushBuffer(); + string str; long i; char* readempty; char* readsimple; + string simplestr; + in & str & cstr & readempty & readsimple & simplestr & i; + CHECK(str == ""); + CHECK(cstr == nullptr); + CHECK(strcmp(readempty,"") == 0); + CHECK(strcmp(readsimple,"simple") == 0); + CHECK(i == 1); + CHECK(simplestr == "simple"); + delete[] readempty; + delete[] empty; + delete[] simple; + delete[] readsimple; + } + SECTION("SharedPtr") + { + testSharedPointer(in, out); + } + SECTION("Pointer") + { + testPointer(in, out); + } + SECTION("Const Pointer") + { + testConstPointer(in, out); + } + SECTION("Multiple inheritance") + { + testMultipleInheritance(in, out); + } + SECTION("Not registered") + { + SharedPtrAndPtrHolder* p = new NotRegisteredForArchive; + REQUIRE_THROWS(out & p, Catch::Contains("not registered for archive")); + } + SECTION("nullptr") + { + testNullPtr(in, out); + } + SECTION("Library Version") + { + testLibraryVersion(in,out); + } +} + +TEST_CASE("BinaryArchive") +{ + SetLibraryVersion("netgen","v6.2.1811"); + auto stream = make_shared(); + BinaryOutArchive out(stream); + BinaryInArchive in(stream); + testArchive(in, out); +} + +TEST_CASE("TextArchive") +{ + SetLibraryVersion("netgen","v6.2.1811"); + auto stream = make_shared(); + TextOutArchive out(stream); + TextInArchive in(stream); + testArchive(in, out); +} diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,37 @@ + +if(ENABLE_UNIT_TESTS) +add_custom_target(unit_tests) + +# Build catch_main test object +message("netgen include dir = ${NETGEN_INCLUDE_DIR_ABSOLUTE} --------------------------------------") +include_directories(${CATCH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../libsrc/include}) +add_library(catch_main STATIC main.cpp) +set_target_properties(catch_main PROPERTIES CXX_STANDARD 17) +add_dependencies(unit_tests catch_main) +add_dependencies(catch_main project_catch) + +# ensure the test targets are built before testing +add_test(NAME unit_tests_built COMMAND ${CMAKE_COMMAND} --build . --target unit_tests --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../.. ) + +macro(add_unit_test name sources) + add_executable(test_${name} ${sources} ) + if (WIN32) + target_link_libraries(test_${name} ngcore catch_main) + else(WIN32) + target_link_libraries(test_${name} ngcore catch_main) + endif(WIN32) + + add_dependencies(unit_tests test_${name}) + add_test(NAME unit_${name} COMMAND test_${name}) + set_tests_properties(unit_${name} PROPERTIES DEPENDS unit_tests_built) +endmacro() + +add_unit_test(archive archive.cpp) +add_unit_test(version version.cpp) + +if(ENABLE_CPP_CORE_GUIDELINES_CHECK) + set_target_properties(test_archive PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}") + set_target_properties(test_version PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}") +endif(ENABLE_CPP_CORE_GUIDELINES_CHECK) + +endif(ENABLE_UNIT_TESTS) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/main.cpp ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/main.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/main.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/main.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,3 @@ + +#define CATCH_CONFIG_MAIN +#include diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/version.cpp ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/version.cpp --- ngsolve-6.2.1810/external_dependencies/netgen/tests/catch/version.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/catch/version.cpp 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,19 @@ + +#include "catch.hpp" +#include <../core/ngcore.hpp> +using namespace ngcore; +using namespace std; + + +TEST_CASE("Version") +{ + VersionInfo v("v6.2.1811-3-asdf"); + CHECK(v.to_string() == "v6.2.1811-3-asdf"); + VersionInfo v2("6.2"); + CHECK(v2.to_string() == "v6.2"); + CHECK(v < "v7"); + CHECK(v >= "6.2"); + CHECK(v > "6.2.1811"); + CHECK(v < "6.2.1811-5"); + CHECK(v == "v6.2.1811-3"); +} diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/CMakeLists.txt ngsolve-6.2.1901/external_dependencies/netgen/tests/CMakeLists.txt --- ngsolve-6.2.1810/external_dependencies/netgen/tests/CMakeLists.txt 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/CMakeLists.txt 2019-01-12 00:19:01.000000000 +0000 @@ -1 +1,2 @@ +add_subdirectory(catch) add_subdirectory(pytest) diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/docker_15.10 ngsolve-6.2.1901/external_dependencies/netgen/tests/docker_15.10 --- ngsolve-6.2.1810/external_dependencies/netgen/tests/docker_15.10 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/docker_15.10 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -FROM ubuntu:15.10 -MAINTAINER Matthias Hochsteger -RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk -ADD . /root/src/netgen diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/docker_16.04 ngsolve-6.2.1901/external_dependencies/netgen/tests/docker_16.04 --- ngsolve-6.2.1810/external_dependencies/netgen/tests/docker_16.04 2018-11-29 09:48:21.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/docker_16.04 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -FROM ubuntu:16.04 -MAINTAINER Matthias Hochsteger -RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk -ADD . /root/src/netgen diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/dockerfile ngsolve-6.2.1901/external_dependencies/netgen/tests/dockerfile --- ngsolve-6.2.1810/external_dependencies/netgen/tests/dockerfile 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/dockerfile 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,5 @@ +FROM ubuntu:18.04 +ENV DEBIAN_FRONTEND=noninteractive +MAINTAINER Matthias Hochsteger +RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk clang-tidy python3-distutils clang +ADD . /root/src/netgen diff -Nru ngsolve-6.2.1810/external_dependencies/netgen/tests/pytest/test_pickling.py ngsolve-6.2.1901/external_dependencies/netgen/tests/pytest/test_pickling.py --- ngsolve-6.2.1810/external_dependencies/netgen/tests/pytest/test_pickling.py 1970-01-01 00:00:00.000000000 +0000 +++ ngsolve-6.2.1901/external_dependencies/netgen/tests/pytest/test_pickling.py 2019-01-12 00:19:01.000000000 +0000 @@ -0,0 +1,89 @@ + +import pickle, numpy + +def test_pickle_csg(): + import netgen.csg as csg + geo = csg.CSGeometry() + geo.Add(csg.Sphere(csg.Pnt(0,0,0), 2).bc("sphere")) + brick = csg.OrthoBrick(csg.Pnt(-3,-3,-3), csg.Pnt(3,3,3)) + geo.Add(csg.Cylinder(csg.Pnt(0,0,0), csg.Pnt(1,0,0), 0.5) * brick) + geo.Add(csg.Ellipsoid(csg.Pnt(0,0,0), csg.Vec(1,0,0), csg.Vec(0,1,0), csg.Vec(0,0,0.5))) + geo.Add(csg.Cone(csg.Pnt(0,0,0), csg.Pnt(3,0,0), 1, 0.5) * brick) + geo.Add(csg.EllipticCone(csg.Pnt(0,0,0), csg.Vec(2,0,0), csg.Vec(0,1,0), 3, 0.5) * brick) + geo.Add(csg.Torus(csg.Pnt(0,0,0), csg.Vec(0,1,0), 0.3, 0.05)) + pts2d = [[1,1], [1,-1], [-1,-1], [-1,1]] + segs = [[0,1], [1,2], [2,3], [3,0]] + curve = csg.SplineCurve2d() + pnrs = [curve.AddPoint(*p) for p in pts2d] + for s in segs: + curve.AddSegment(pnrs[s[0]], pnrs[s[1]]) + geo.Add(csg.Revolution(csg.Pnt(0,0,0), csg.Pnt(1,0,0), curve)) + path = csg.SplineCurve3d() + pnts = [(0,0,0), (2,0,0), (2,2,0)] + segs = [(0,1,2)] + for pnt in pnts: + path.AddPoint (*pnt) + + for seg in segs: + path.AddSegment (*seg) + geo.Add(csg.Extrusion(path, curve, csg.Vec(0,0,1))) + + geo_dump = pickle.dumps(geo) + geo2 = pickle.loads(geo_dump) + vd1 = geo._visualizationData() + vd2 = geo2._visualizationData() + for val1, val2 in zip(vd1.values(), vd2.values()): + assert numpy.array_equal(val1, val2) + +def test_pickle_stl(): + import netgen.stl as stl + geo = stl.LoadSTLGeometry("../../tutorials/hinge.stl") + geo_dump = pickle.dumps(geo) + geo2 = pickle.loads(geo_dump) + vd1 = geo._visualizationData() + vd2 = geo2._visualizationData() + for val1, val2 in zip(vd1.values(), vd2.values()): + assert numpy.array_equal(val1, val2) + + +def test_pickle_occ(): + try: + import netgen.NgOCC as occ + except: + import pytest + pytest.skip("can't import occ") + geo = occ.LoadOCCGeometry("../../tutorials/frame.step") + geo_dump = pickle.dumps(geo) + geo2 = pickle.loads(geo_dump) + vd1 = geo._visualizationData() + vd2 = geo2._visualizationData() + # TODO: it looks fine, but tests fail, so I assume we loose some info? + # for val1, val2 in zip(vd1.values(), vd2.values()): + # assert numpy.allclose(val1, val2, rtol=0.01) + +def test_pickle_geom2d(): + import netgen.geom2d as geom2d + geo = geom2d.SplineGeometry() + + # point coordinates ... + pnts = [ (0,0), (1,0), (1,0.6), (0,0.6), \ + (0.2,0.6), (0.8,0.6), (0.8,0.8), (0.2,0.8), \ + (0.5,0.15), (0.65,0.3), (0.5,0.45), (0.35,0.3) ] + pnums = [geo.AppendPoint(*p) for p in pnts] + + # start-point, end-point, boundary-condition, domain on left side, domain on right side: + lines = [ (0,1,1,1,0), (1,2,2,1,0), (2,5,2,1,0), (5,4,2,1,2), (4,3,2,1,0), (3,0,2,1,0), \ + (5,6,2,2,0), (6,7,2,2,0), (7,4,2,2,0), \ + (8,9,2,3,1), (9,10,2,3,1), (10,11,2,3,1), (11,8,2,3,1) ] + + for p1,p2,bc,left,right in lines: + geo.Append( ["line", pnums[p1], pnums[p2]], bc=bc, leftdomain=left, rightdomain=right) + geo_dump = pickle.dumps(geo) + geo2 = pickle.loads(geo_dump) + vd1 = geo._visualizationData() + vd2 = geo2._visualizationData() + for val1, val2 in zip(vd1.values(), vd2.values()): + assert numpy.array_equal(val1, val2) + +if __name__ == "__main__": + test_pickle_csg() diff -Nru ngsolve-6.2.1810/fem/coefficient.cpp ngsolve-6.2.1901/fem/coefficient.cpp --- ngsolve-6.2.1810/fem/coefficient.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/coefficient.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -2961,6 +2961,8 @@ acf_then->IsComplex() || acf_else->IsComplex()), cf_if(acf_if), cf_then(acf_then), cf_else(acf_else) { + if (acf_then->Dimension() != acf_else->Dimension()) + throw Exception(string("In IfPosCoefficientFunction: dim(cf_then) == ") + ToLiteral(acf_then->Dimension()) + string(" != dim(cf_else) == ") + ToLiteral(acf_else->Dimension())); SetDimensions(cf_then->Dimensions()); } diff -Nru ngsolve-6.2.1810/fem/coefficient.hpp ngsolve-6.2.1901/fem/coefficient.hpp --- ngsolve-6.2.1810/fem/coefficient.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/coefficient.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -1266,7 +1266,7 @@ c1->NonZeroPattern(ud, v1, d1, dd1); for (int i = 0; i < nonzero.Size(); i++) { - if (name == "-") // actually not used that way + if (name == "-" || name == " ") // "-" actually not used that way { nonzero(i) = v1(i); nonzero_deriv(i) = d1(i); @@ -1286,7 +1286,7 @@ FlatVector> values) const override { auto v1 = input[0]; - if (name == "-") // actually not used that way + if (name == "-" || name == " ") // "-" actually not used that way { values = v1; } diff -Nru ngsolve-6.2.1810/fem/l2hofe.hpp ngsolve-6.2.1901/fem/l2hofe.hpp --- ngsolve-6.2.1810/fem/l2hofe.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/l2hofe.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -138,6 +138,7 @@ #include #include +#ifdef NONE namespace ngfem { template <> inline void L2HighOrderFE :: @@ -152,7 +153,7 @@ for (int ix = 0; ix <= order; ix++) mass(ix) = 1.0 / (2 * ix + 1); } - + template <> inline void L2HighOrderFE :: GetDiagMassMatrix(FlatVector<> mass) const { @@ -170,14 +171,6 @@ } - template <> inline void L2HighOrderFE :: - GetDiagMassMatrix(FlatVector<> mass) const - { - for (int ix = 0, ii = 0; ix <= order; ix++) - for (int iy = 0; iy <= order - ix; iy++) - for (int iz = 0; iz <= order - ix-iy; iz++, ii++) - mass(ii) = 1.0 / ((2 * ix + 1) * (2 * ix + 2 * iy + 2) * (2 * ix + 2 * iy + 2 * iz + 3)); - } template <> inline void L2HighOrderFE :: GetDiagMassMatrix(FlatVector<> mass) const @@ -187,9 +180,9 @@ for (int iz = 0; iz <= order; iz++, ii++) mass(ii) = 1.0 / ((2 * ix + 1) * (2 * iy + 1) * (2 * iz + 1)); } - - } +#endif + #else #define L2HOFE_EXTERN extern @@ -205,25 +198,27 @@ namespace ngfem { L2HOFE_EXTERN template class L2HighOrderFE; + L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_POINT, DGFiniteElement<0> >; + extern template class L2HighOrderFE; + extern template class T_ScalarFiniteElement, ET_SEGM, DGFiniteElement<1> >; + extern template class L2HighOrderFE; + extern template class T_ScalarFiniteElement, ET_TRIG, DGFiniteElement<2> >; + L2HOFE_EXTERN template class L2HighOrderFE; - + L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_QUAD, DGFiniteElement<2> >; + extern template class L2HighOrderFE; + extern template class T_ScalarFiniteElement, ET_TET, DGFiniteElement<3> >; + L2HOFE_EXTERN template class L2HighOrderFE; L2HOFE_EXTERN template class L2HighOrderFE; L2HOFE_EXTERN template class L2HighOrderFE; - L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_POINT, DGFiniteElement<0> >; - extern template class T_ScalarFiniteElement, ET_SEGM, DGFiniteElement<1> >; - extern template class T_ScalarFiniteElement, ET_TRIG, DGFiniteElement<2> >; - L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_QUAD, DGFiniteElement<2> >; - - extern template class T_ScalarFiniteElement, ET_TET, DGFiniteElement<3> >; L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_PRISM, DGFiniteElement<3> >; L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_PYRAMID, DGFiniteElement<3> >; L2HOFE_EXTERN template class T_ScalarFiniteElement, ET_HEX, DGFiniteElement<3> >; - } #endif diff -Nru ngsolve-6.2.1810/fem/l2hofe_impl.hpp ngsolve-6.2.1901/fem/l2hofe_impl.hpp --- ngsolve-6.2.1810/fem/l2hofe_impl.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/l2hofe_impl.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -250,7 +250,46 @@ void L2HighOrderFE :: GetDiagMassMatrix (FlatVector<> mass) const { - DGFiniteElement::DIM>::GetDiagMassMatrix (mass); + switch (ET) + { + case ET_POINT: + mass(0) = 1; + break; + + case ET_SEGM: + for (int ix = 0; ix <= order; ix++) + mass(ix) = 1.0 / (2 * ix + 1); + break; + + case ET_TRIG: + for (int ix = 0, ii = 0; ix <= order; ix++) + for (int iy = 0; iy <= order - ix; iy++, ii++) + mass(ii) = 1.0 / ((2 * ix + 1) * (2 * ix + 2 * iy + 2)); + break; + + case ET_QUAD: + for (int ix = 0, ii = 0; ix <= order; ix++) + for (int iy = 0; iy <= order; iy++, ii++) + mass(ii) = 1.0 / ((2 * ix + 1) * (2 * iy + 1)); + break; + + case ET_TET: + for (int ix = 0, ii = 0; ix <= order; ix++) + for (int iy = 0; iy <= order - ix; iy++) + for (int iz = 0; iz <= order - ix-iy; iz++, ii++) + mass(ii) = 1.0 / ((2 * ix + 1) * (2 * ix + 2 * iy + 2) * (2 * ix + 2 * iy + 2 * iz + 3)); + break; + + case ET_HEX: + for (int ix = 0, ii = 0; ix <= order; ix++) + for (int iy = 0; iy <= order; iy++) + for (int iz = 0; iz <= order; iz++, ii++) + mass(ii) = 1.0 / ((2 * ix + 1) * (2 * iy + 1) * (2 * iz + 1)); + break; + + default: + DGFiniteElement::DIM>::GetDiagMassMatrix (mass); + } } diff -Nru ngsolve-6.2.1810/fem/l2hofe_tet.cpp ngsolve-6.2.1901/fem/l2hofe_tet.cpp --- ngsolve-6.2.1810/fem/l2hofe_tet.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/l2hofe_tet.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -4,7 +4,7 @@ /* Date: 6. Feb. 2003 */ /*********************************************************************/ -// #define FILE_L2HOFE_CPP +// #define FILE_L2HOFE_TET_CPP #include #include @@ -14,6 +14,17 @@ namespace ngfem { + /* + template <> inline void L2HighOrderFE :: + GetDiagMassMatrix(FlatVector<> mass) const + { + for (int ix = 0, ii = 0; ix <= order; ix++) + for (int iy = 0; iy <= order - ix; iy++) + for (int iz = 0; iz <= order - ix-iy; iz++, ii++) + mass(ii) = 1.0 / ((2 * ix + 1) * (2 * ix + 2 * iy + 2) * (2 * ix + 2 * iy + 2 * iz + 3)); + } + */ + template class L2HighOrderFE; template class T_ScalarFiniteElement, ET_TET, DGFiniteElement<3> >; diff -Nru ngsolve-6.2.1810/fem/l2hofe_trig.cpp ngsolve-6.2.1901/fem/l2hofe_trig.cpp --- ngsolve-6.2.1810/fem/l2hofe_trig.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/l2hofe_trig.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -13,6 +13,17 @@ namespace ngfem { + + /* + template <> inline void L2HighOrderFE :: + GetDiagMassMatrix(FlatVector<> mass) const + { + for (int ix = 0, ii = 0; ix <= order; ix++) + for (int iy = 0; iy <= order - ix; iy++, ii++) + mass(ii) = 1.0 / ((2 * ix + 1) * (2 * ix + 2 * iy + 2)); + } + */ + template class L2HighOrderFE; template class T_ScalarFiniteElement, ET_TRIG, DGFiniteElement<2> >; diff -Nru ngsolve-6.2.1810/fem/python_fem.cpp ngsolve-6.2.1901/fem/python_fem.cpp --- ngsolve-6.2.1810/fem/python_fem.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/python_fem.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -1426,6 +1426,11 @@ .def("__timing__", &FiniteElement::Timing) ; + py::class_, FiniteElement> + (m, "MixedFE", "pair of finite elements for trial and test-functions") + .def(py::init()) + ; + py::class_, FiniteElement> (m, "ScalarFE", "a scalar-valued finite element") @@ -1999,14 +2004,19 @@ try { if (complex) - { + { Matrix mat(fe.GetNDof() * self->GetDimension()); self->CalcElementMatrix(fe,trafo,mat,lh); return py::cast(mat); } else { - Matrix<> mat(fe.GetNDof() * self->GetDimension()); + const MixedFiniteElement * mixedfe = dynamic_cast (&fe); + const FiniteElement & fe_trial = mixedfe ? mixedfe->FETrial() : fe; + const FiniteElement & fe_test = mixedfe ? mixedfe->FETest() : fe; + + Matrix<> mat(fe_test.GetNDof() * self->GetDimension(), + fe_trial.GetNDof() * self->GetDimension()); self->CalcElementMatrix (fe, trafo, mat, lh); return py::cast(mat); } diff -Nru ngsolve-6.2.1810/fem/symbolicintegrator.cpp ngsolve-6.2.1901/fem/symbolicintegrator.cpp --- ngsolve-6.2.1810/fem/symbolicintegrator.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/fem/symbolicintegrator.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -1629,7 +1629,10 @@ { HeapReset hr(lh); ngfem::ELEMENT_TYPE etfacet = transform.FacetType (k); - SIMD_IntegrationRule ir_facet(etfacet, fel_trial.Order()+fel_test.Order()); + SIMD_IntegrationRule ir_facet1(etfacet, fel_trial.Order()+fel_test.Order()); + SIMD_IntegrationRule & ir_facet(userdefined_simd_intrules[etfacet] ? + *userdefined_simd_intrules[etfacet] + : ir_facet1); auto & ir_facet_vol = transform(k, ir_facet, lh); auto & mir = trafo(ir_facet_vol, lh); diff -Nru ngsolve-6.2.1810/linalg/basematrix.cpp ngsolve-6.2.1901/linalg/basematrix.cpp --- ngsolve-6.2.1810/linalg/basematrix.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/basematrix.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -97,6 +97,12 @@ MultAdd (1, x, y); } + void BaseMatrix :: MultTrans (const BaseVector & x, BaseVector & y) const + { + y = 0; + MultTransAdd (1, x, y); + } + void BaseMatrix :: MultAdd (double s, const BaseVector & x, BaseVector & y) const { // cout << "Warning: BaseMatrix::MultAdd(double), this = " << typeid(*this).name() << endl; diff -Nru ngsolve-6.2.1810/linalg/basematrix.hpp ngsolve-6.2.1901/linalg/basematrix.hpp --- ngsolve-6.2.1810/linalg/basematrix.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/basematrix.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -92,8 +92,10 @@ /// creates a matching vector (for square matrices) virtual AutoVector CreateVector () const; - /// y = matrix * x. Multadd should be implemented, instead + /// y = matrix * x. virtual void Mult (const BaseVector & x, BaseVector & y) const; + /// + virtual void MultTrans (const BaseVector & x, BaseVector & y) const; /// y += s matrix * x virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const; /// y += s matrix * x @@ -251,6 +253,16 @@ virtual AutoVector CreateRowVector () const override { return bm.CreateColVector(); } virtual AutoVector CreateColVector () const override { return bm.CreateRowVector(); } + + virtual void Mult (const BaseVector & x, BaseVector & y) const override + { + bm.MultTrans (x, y); + } + + virtual void MultTrans (const BaseVector & x, BaseVector & y) const override + { + bm.Mult (x, y); + } /// virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override @@ -313,20 +325,37 @@ virtual AutoVector CreateColVector () const override { return bma.CreateColVector(); } /// + virtual void Mult (const BaseVector & x, BaseVector & y) const override + { + static Timer t("ProductMatrix::Mult"); RegionTimer reg(t); + bmb.Mult (x, tempvec); + bma.Mult (tempvec, y); + } + + virtual void MultTrans (const BaseVector & x, BaseVector & y) const override + { + static Timer t("ProductMatrix::Mult"); RegionTimer reg(t); + bma.MultTrans (x, tempvec); + bmb.MultTrans (tempvec, y); + } + virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ProductMatrix::MultAdd"); RegionTimer reg(t); bmb.Mult (x, tempvec); bma.MultAdd (s, tempvec, y); } /// virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ProductMatrix::MultAdd complex"); RegionTimer reg(t); bmb.Mult (x, tempvec); bma.MultAdd (s, tempvec, y); } /// virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ProductMatrix::MultTransAdd"); RegionTimer reg(t); tempvec = 0.0; bma.MultTransAdd (1, x, tempvec); bmb.MultTransAdd (s, tempvec, y); @@ -334,6 +363,7 @@ /// virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ProductMatrix::MultTransAdd complex"); RegionTimer reg(t); tempvec = 0.0; bma.MultTransAdd (1, x, tempvec); bmb.MultTransAdd (s, tempvec, y); @@ -397,28 +427,58 @@ return bmb.CreateColVector(); } } + + virtual void Mult (const BaseVector & x, BaseVector & y) const override + { + static Timer t("SumMatrix::Mult"); RegionTimer reg(t); + if (a == 1) + bma.Mult (x, y); + else + { + y = 0.0; + bma.MultAdd (a, x, y); + } + bmb.MultAdd (b, x, y); + } + + virtual void MultTrans (const BaseVector & x, BaseVector & y) const override + { + static Timer t("SumMatrix::MultTrans"); RegionTimer reg(t); + if (a == 1) + bma.MultTrans (x, y); + else + { + y = 0.0; + bma.MultTransAdd (a, x, y); + } + bmb.MultTransAdd (b, x, y); + } /// virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("SumMatrix::MultAdd"); RegionTimer reg(t); bma.MultAdd (a*s, x, y); bmb.MultAdd (b*s, x, y); } /// virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("SumMatrix::MultAdd complex"); RegionTimer reg(t); bma.MultAdd (a*s, x, y); bmb.MultAdd (b*s, x, y); } /// virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("SumMatrix::MultTransAdd"); RegionTimer reg(t); bma.MultTransAdd (a*s, x, y); bmb.MultTransAdd (b*s, x, y); } /// virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("SumMatrix::MultAdd complex"); RegionTimer reg(t); bma.MultTransAdd (a*s, x, y); bmb.MultTransAdd (b*s, x, y); } @@ -456,21 +516,25 @@ /// virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ScaleMatrix::MultAdd"); RegionTimer reg(t); bm.MultAdd (s*scale, x, y); } /// virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ScaleMatrix::MultAdd complex"); RegionTimer reg(t); bm.MultAdd (s*scale, x, y); } /// virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ScaleMatrix::MultTransAdd"); RegionTimer reg(t); bm.MultTransAdd (s*scale, x, y); } /// virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("ScaleMatrix::MultTransAdd complex"); RegionTimer reg(t); bm.MultTransAdd (s*scale, x, y); } @@ -509,23 +573,38 @@ virtual bool IsComplex() const override { return is_complex; } /// + virtual void Mult (const BaseVector & x, BaseVector & y) const override + { + static Timer t("IdentityMatrix::Mult"); RegionTimer reg(t); + y = x; + } + virtual void MultTrans (const BaseVector & x, BaseVector & y) const override + { + static Timer t("IdentityMatrix::MultTrans"); RegionTimer reg(t); + y = x; + } + /// virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("IdentityMatrix::MultAdd"); RegionTimer reg(t); y += s*x; } /// virtual void MultAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("IdentityMatrix::MultAdd Complex"); RegionTimer reg(t); y += s*x; } /// virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override { + static Timer t("IdentityMatrix::MultTransAdd"); RegionTimer reg(t); y += s*x; } /// virtual void MultTransAdd (Complex s, const BaseVector & x, BaseVector & y) const override { + static Timer t("IdentityMatrix::MultTransAdd Complex"); RegionTimer reg(t); y += s*x; } diff -Nru ngsolve-6.2.1810/linalg/blockjacobi.cpp ngsolve-6.2.1901/linalg/blockjacobi.cpp --- ngsolve-6.2.1810/linalg/blockjacobi.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/blockjacobi.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -543,8 +543,8 @@ void BlockJacobiPrecond :: MultTransAdd (TSCAL s, const BaseVector & x, BaseVector & y) const { - static int timer = NgProfiler::CreateTimer ("BlockJacobi::MultTransAdd"); - NgProfiler::RegionTimer reg (timer); + static Timer timer("BlockJacobi::MultTransAdd"); + RegionTimer reg (timer); FlatVector fx = x.FV (); FlatVector fy = y.FV (); diff -Nru ngsolve-6.2.1810/linalg/elementbyelement.cpp ngsolve-6.2.1901/linalg/elementbyelement.cpp --- ngsolve-6.2.1810/linalg/elementbyelement.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/elementbyelement.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -669,6 +669,240 @@ template class ElementByElementMatrix; - template class ElementByElementMatrix; + template class ElementByElementMatrix; + + + ConstantElementByElementMatrix :: + ConstantElementByElementMatrix (size_t ah, size_t aw, Matrix<> amatrix, + Table acol_dnums, Table arow_dnums) + : h(ah), w(aw), matrix(amatrix), col_dnums(move(acol_dnums)), row_dnums(move(arow_dnums)) + { + disjoint_cols = true; + disjoint_rows = true; + + BitArray used_col(h); + used_col.Clear(); + for (auto col : col_dnums) + for (auto d : col) + { + if (used_col.Test(d)) disjoint_cols = false; + used_col.Set(d); + } + + BitArray used_row(w); + used_row.Clear(); + for (auto row : row_dnums) + for (auto d : row) + { + if (used_row.Test(d)) disjoint_rows = false; + used_row.Set(d); + } + + cout << "disjoint_rows = " << disjoint_rows << ", disjoint_cols = " << disjoint_cols << endl; + + + + if (!disjoint_rows) + { + Array locks(w); + size_t nblocks = row_dnums.Size(); + Array col(nblocks); + col = -1; + + int maxcolor = 0; + int basecol = 0; + Array mask(w); + + atomic found(0); + size_t cnt = row_dnums.Size(); + + while (found < cnt) + { + ParallelForRange + (mask.Size(), + [&] (IntRange myrange) { mask[myrange] = 0; }); + + ParallelForRange + (nblocks, [&] (IntRange myrange) + { + Array dofs; + size_t myfound = 0; + + for (size_t nr : myrange) + { + if (col[nr] >= 0) continue; + + unsigned check = 0; + dofs = row_dnums[nr]; + + QuickSort (dofs); // sort to avoid dead-locks + + for (auto d : dofs) + locks[d].lock(); + + for (auto d : dofs) + check |= mask[d]; + + if (check != UINT_MAX) // 0xFFFFFFFF) + { + myfound++; + unsigned checkbit = 1; + int color = basecol; + while (check & checkbit) + { + color++; + checkbit *= 2; + } + + col[nr] = color; + if (color > maxcolor) maxcolor = color; + + for (auto d : dofs) + mask[d] |= checkbit; + } + + for (auto d : dofs) + locks[d].unlock(); + } + found += myfound; + }); + + basecol += 8*sizeof(unsigned int); // 32; + } + + Array cntcol(maxcolor+1); + cntcol = 0; + + for (auto nr : Range(nblocks)) + cntcol[col[nr]]++; + cout << "cntcol = " << cntcol << endl; + row_coloring = Table (cntcol); + + cntcol = 0; + for (auto nr : Range(nblocks)) + row_coloring[col[nr]][cntcol[col[nr]]++] = nr; + } + } + + AutoVector ConstantElementByElementMatrix :: CreateRowVector () const + { + return make_shared> (w); + } + + AutoVector ConstantElementByElementMatrix :: CreateColVector () const + { + return make_shared> (h); + } + + + void ConstantElementByElementMatrix :: MultAdd (double s, const BaseVector & x, BaseVector & y) const + { + static Timer ts("ConstantEBE mult sequential"); + static Timer tp("ConstantEBE mult parallel"); + static Timer tpmult("ConstantEBE mult parallel mult"); + + auto fx = x.FV(); + auto fy = y.FV(); + + if (!disjoint_cols) + { + RegionTimer reg(ts); + Vector<> hx(matrix.Width()); + Vector<> hy(matrix.Height()); + for (size_t i = 0; i < row_dnums.Size(); i++) + { + hx = fx(row_dnums[i]); + hy = matrix * hx; + fy(col_dnums[i]) += s * hy; + } + } + else + { + RegionTimer reg(tp); + ParallelForRange + (row_dnums.Size(), [&] (IntRange r) + { + /* + Vector<> hx(matrix.Width()); + Vector<> hy(matrix.Height()); + for (auto i : r) + { + hx = fx(row_dnums[i]); + hy = matrix * hx; + fy(col_dnums[i]) += s * hy; + } + */ + constexpr size_t BS = 128; + Matrix<> hx(BS, matrix.Width()); + Matrix<> hy(BS, matrix.Height()); + + for (size_t bi = r.First(); bi < r.Next(); bi+= BS) + { + size_t li = min2(bi+BS, r.Next()); + size_t num = li-bi; + + for (size_t i = 0; i < num; i++) + hx.Row(i) = fx(row_dnums[bi+i]); + { + RegionTracer rt(TaskManager::GetThreadId(), tpmult); + hy.Rows(0, num) = hx.Rows(0, num) * Trans(matrix); + } + for (size_t i = 0; i < num; i++) + fy(col_dnums[bi+i]) += s * hy.Row(i); + } + }); + } + } + + void ConstantElementByElementMatrix :: MultTransAdd (double s, const BaseVector & x, BaseVector & y) const + { + static Timer ts("ConstantEBE mult trans"); + static Timer tp("ConstantEBE mult trans parallel"); + RegionTimer reg(ts); + + auto fx = x.FV(); + auto fy = y.FV(); + + if (!disjoint_rows) + { // use coloring + RegionTimer reg(tp); + + for (auto col : row_coloring) + ParallelForRange + (col.Size(), [&] (IntRange r) + { + constexpr size_t BS = 128; + Matrix<> hx(BS, matrix.Height()); + Matrix<> hy(BS, matrix.Width()); + + for (size_t bi = r.First(); bi < r.Next(); bi+= BS) + { + size_t li = min2(bi+BS, r.Next()); + size_t num = li-bi; + + for (size_t i = 0; i < num; i++) + hx.Row(i) = fx(col_dnums[col[bi+i]]); + + hy.Rows(0, num) = hx.Rows(0, num) * matrix; + + for (size_t i = 0; i < num; i++) + fy(row_dnums[col[bi+i]]) += s * hy.Row(i); + } + }); + } + else + { + Vector<> hx(matrix.Height()); + Vector<> hy(matrix.Width()); + for (size_t i = 0; i < row_dnums.Size(); i++) + { + hx = fx(col_dnums[i]); + hy = Trans(matrix) * hx; + fy(row_dnums[i]) += s * hy; + } + } + } + + } diff -Nru ngsolve-6.2.1810/linalg/elementbyelement.hpp ngsolve-6.2.1901/linalg/elementbyelement.hpp --- ngsolve-6.2.1810/linalg/elementbyelement.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/elementbyelement.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -120,6 +120,26 @@ virtual size_t NZE () const { return GetNZE(); } }; + + class NGS_DLL_HEADER ConstantElementByElementMatrix : public BaseMatrix + { + size_t h, w; + Matrix<> matrix; + Table col_dnums; + Table row_dnums; + bool disjoint_rows, disjoint_cols; + Table row_coloring, col_coloring; + public: + ConstantElementByElementMatrix (size_t ah, size_t aw, Matrix<> amatrix, + Table acol_dnums, Table arow_dnums); + + virtual void MultAdd (double s, const BaseVector & x, BaseVector & y) const override; + virtual void MultTransAdd (double s, const BaseVector & x, BaseVector & y) const override; + + virtual AutoVector CreateRowVector () const override; + virtual AutoVector CreateColVector () const override; + }; + } #endif diff -Nru ngsolve-6.2.1810/linalg/jacobi.cpp ngsolve-6.2.1901/linalg/jacobi.cpp --- ngsolve-6.2.1810/linalg/jacobi.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/jacobi.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -61,12 +61,30 @@ FlatVector fy = y.FV (); if (!inner) + /* for (int i = 0; i < height; i++) fy(i) += s * (invdiag[i] * fx(i)); - else + */ + ParallelForRange (height, + [fx, fy, s, this] (IntRange r) + { + for (auto i : r) + fy(i) += s * (this->invdiag[i] * fx(i)); + }); + else + /* for (int i = 0; i < height; i++) if (inner->Test(i)) fy(i) += s * (invdiag[i] * fx(i)); + */ + ParallelForRange (height, + [fx, fy, s, this] (IntRange r) + { + for (auto i : r) + if (this->inner->Test(i)) + fy(i) += s * (this->invdiag[i] * fx(i)); + }); + } diff -Nru ngsolve-6.2.1810/linalg/python_linalg.cpp ngsolve-6.2.1901/linalg/python_linalg.cpp --- ngsolve-6.2.1810/linalg/python_linalg.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/python_linalg.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -72,6 +72,25 @@ auto cvalues = makeCArray(values); return SparseMatrix::CreateFromCOO (cindi,cindj,cvalues, h,w); }, py::arg("indi"), py::arg("indj"), py::arg("values"), py::arg("h"), py::arg("w")) + + .def_static("CreateFromElmat", + [] (py::list coldnums, py::list rowdnums, py::list elmats, size_t h, size_t w) + { + auto cdnums1 = makeCTable(coldnums); + auto rdnums1 = makeCTable(rowdnums); + auto sparsemat = make_shared>(h, w, cdnums1, rdnums1, false); + sparsemat->SetZero(); + auto cdnums = makeCTable(coldnums); + auto rdnums = makeCTable(rowdnums); + for (int i = 0; i < py::len(elmats); i++) + { + const Matrix & m = py::cast&> (elmats[i]); + sparsemat -> AddElementMatrix(cdnums[i], rdnums[i], m, false); + } + return sparsemat; + // auto cvalues = makeCArray(values); + // return SparseMatrix::CreateFromCOO (cindi,cindj,cvalues, h,w); + }, py::arg("col_ind"), py::arg("row_ind"), py::arg("matrices"), py::arg("h"), py::arg("w")) .def("CreateTranspose", [] (const SparseMatrix & sp) { return TransposeMatrix (sp); }, "Return transposed matrix") @@ -677,7 +696,42 @@ py::class_, shared_ptr>, BaseMatrix> (m, "S_BaseMatrixC", "base sparse matrix"); + py::class_, BaseMatrix> + (m, "ConstEBEMatrix") + .def(py::init<> ([] (size_t h, size_t w, Matrix<> mat, + py::list pycdofs, py::list pyrdofs) + { + /* + size_t n = py::len(pyrdofs); + Array entrysize(n); + for (size_t i = 0; i < n; i++) + entrysize[i] = py::len(pyrdofs[i]); + Table rdofs(entrysize); + for (size_t i = 0; i < n; i++) + { + const py::object & obj = pyrdofs[i]; + rdofs[i] = makeCArray (obj); + } + for (size_t i = 0; i < n; i++) + entrysize[i] = py::len(pycdofs[i]); + Table cdofs(entrysize); + for (size_t i = 0; i < n; i++) + { + const py::object & obj = pycdofs[i]; + cdofs[i] = makeCArray (obj); + } + */ + auto rdofs = makeCTable (pyrdofs); + auto cdofs = makeCTable (pycdofs); + + return make_shared (h, w, mat, + std::move(cdofs), std::move(rdofs)); + }), + py::arg("h"), py::arg("w"), py::arg("matrix"), + py::arg("col_ind"), py::arg("row_ind")) + ; + py::class_> (m, "BlockMatrix") .def(py::init<> ([] (vector>> mats) { @@ -877,15 +931,16 @@ )raw_string")) ; - m.def("EigenValues_Preconditioner", [](const BaseMatrix & mat, const BaseMatrix & pre) { + m.def("EigenValues_Preconditioner", [](const BaseMatrix & mat, const BaseMatrix & pre, double tol) { EigenSystem eigen(mat, pre); + eigen.SetPrecision(tol); eigen.Calc(); Vector ev(eigen.NumEigenValues()); for (size_t i = 0; i < ev.Size(); i++) ev[i] = eigen.EigenValue(i+1); return ev; }, - py::arg("mat"), py::arg("pre"), + py::arg("mat"), py::arg("pre"), py::arg("tol")=1e-10, "Calculate eigenvalues of pre * mat, where pre and mat are positive definite matrices.\n" "The typical usecase of this function is to calculate the condition number of a preconditioner." "It uses the Lanczos algorithm and bisection for the tridiagonal matrix" diff -Nru ngsolve-6.2.1810/linalg/sparsecholesky.hpp ngsolve-6.2.1901/linalg/sparsecholesky.hpp --- ngsolve-6.2.1810/linalg/sparsecholesky.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/sparsecholesky.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -247,6 +247,10 @@ virtual void Mult (const BaseVector & x, BaseVector & y) const; virtual void MultAdd (TSCAL_VEC s, const BaseVector & x, BaseVector & y) const; + virtual void MultTransAdd (TSCAL_VEC s, const BaseVector & x, BaseVector & y) const + { + MultAdd (s, x, y); + } virtual AutoVector CreateVector () const { diff -Nru ngsolve-6.2.1810/linalg/special_matrix.cpp ngsolve-6.2.1901/linalg/special_matrix.cpp --- ngsolve-6.2.1810/linalg/special_matrix.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/linalg/special_matrix.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -54,11 +54,13 @@ void Embedding :: MultAdd (double s, const BaseVector & x, BaseVector & y) const { + static Timer t("Embedding::MultAdd"); RegionTimer reg(t); y.Range(range) += s*x; } void Embedding :: MultTransAdd (double s, const BaseVector & x, BaseVector & y) const { + static Timer t("Embedding::MultAddTrans"); RegionTimer reg(t); y += s*x.Range(range); } diff -Nru ngsolve-6.2.1810/multigrid/prolongation.cpp ngsolve-6.2.1901/multigrid/prolongation.cpp --- ngsolve-6.2.1810/multigrid/prolongation.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/multigrid/prolongation.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -30,6 +30,23 @@ { if (ma->GetNLevels() > nvlevel.Size()) nvlevel.Append (ma->GetNV()); + + if (nvlevel.Size() > 1) + { + // if we have a transitive dependency within one level + // we cannot trivially prolongate in parallel + int finelevel = nvlevel.Size()-1; + size_t nc = nvlevel[finelevel-1]; + size_t nf = nvlevel[finelevel]; + auto & mesh = *ma; + ParallelFor (IntRange(nc, nf), [&mesh, nc, this] (size_t i) + { + auto parents = mesh.GetParentNodes (i); + if (parents[0] >= nc || parents[1] >= nc) + this->allow_parallel = false; + }); + + } } @@ -43,11 +60,21 @@ { FlatVector<> fv = v.FV(); fv.Range (nf, fv.Size()) = 0; - for (size_t i = nc; i < nf; i++) + if (allow_parallel) { - auto parents = ma->GetParentNodes (i); - fv(i) = 0.5 * (fv(parents[0]) + fv(parents[1])); + auto & mesh = *ma; + ParallelFor (IntRange(nc, nf), [fv, &mesh] (size_t i) + { + auto parents = mesh.GetParentNodes (i); + fv(i) = 0.5 * (fv(parents[0]) + fv(parents[1])); + }); } + else + for (size_t i = nc; i < nf; i++) + { + auto parents = ma->GetParentNodes (i); + fv(i) = 0.5 * (fv(parents[0]) + fv(parents[1])); + } } else { @@ -69,17 +96,33 @@ size_t nc = nvlevel[finelevel-1]; size_t nf = nvlevel[finelevel]; - FlatSysVector<> fv = v.SV(); - - for (size_t i = nf; i-- > nc; ) - { - auto parents = ma->GetParentNodes (i); - fv(parents[0]) += 0.5 * fv(i); - fv(parents[1]) += 0.5 * fv(i); - } + if (v.EntrySize() == 1) + { + FlatVector<> fv = v.FV(); + for (size_t i = nf; i-- > nc; ) + { + auto parents = ma->GetParentNodes (i); + fv(parents[0]) += 0.5 * fv(i); + fv(parents[1]) += 0.5 * fv(i); + } + fv.Range(nf, fv.Size()) = 0; + } + else + { + FlatSysVector<> fv = v.SV(); + for (size_t i = nf; i-- > nc; ) + { + auto parents = ma->GetParentNodes (i); + fv(parents[0]) += 0.5 * fv(i); + fv(parents[1]) += 0.5 * fv(i); + } + fv.Range(nf, fv.Size()) = 0; + } + /* for (size_t i = nf; i < fv.Size(); i++) fv(i) = 0; + */ } diff -Nru ngsolve-6.2.1810/multigrid/prolongation.hpp ngsolve-6.2.1901/multigrid/prolongation.hpp --- ngsolve-6.2.1810/multigrid/prolongation.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/multigrid/prolongation.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -43,6 +43,7 @@ { shared_ptr ma; Array nvlevel; + bool allow_parallel = true; public: LinearProlongation(shared_ptr ama) : ma(ama) { ; } diff -Nru ngsolve-6.2.1810/ngstd/archive_base.hpp ngsolve-6.2.1901/ngstd/archive_base.hpp --- ngsolve-6.2.1810/ngstd/archive_base.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/archive_base.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,135 +0,0 @@ -#ifndef NGS_ARCHIVE_BASE -#define NGS_ARCHIVE_BASE - -// copied from netgen - -#include -#include - -namespace ngstd -{ - - class Archive - { - bool is_output; - public: - Archive (bool ais_output) : is_output(ais_output) { ; } - virtual ~Archive() { ; } - - bool Output () { return is_output; } - bool Input () { return !is_output; } - - virtual Archive & operator & (double & d) = 0; - virtual Archive & operator & (int & i) = 0; - virtual Archive & operator & (long & i) = 0; - virtual Archive & operator & (size_t & i) = 0; - virtual Archive & operator & (short & i) = 0; - virtual Archive & operator & (unsigned char & i) = 0; - virtual Archive & operator & (bool & b) = 0; - virtual Archive & operator & (string & str) = 0; - virtual Archive & operator & (char *& str) = 0; - - template - Archive & Do (T * data, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; - - - virtual Archive & Do (double * d, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; - - virtual Archive & Do (int * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (long * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (size_t * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (short * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (unsigned char * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (bool * b, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; }; - - - // nvirtual Archive & Do (string * str, size_t n) - // { for (size_t j = 0; j < n; j++) { (*this) & str[j]; }; return *this; }; - // virtual Archive & operator & (char *& str) = 0; - - - // archive a pointer ... - - int cnt = 0; - std::map ptr2nr; - std::vector nr2ptr; - - template - Archive & operator& (T *& p) - { - if (Output()) - { - if (!p) - { - int m2 = -2; - (*this) & m2; - return *this; - } - auto pos = ptr2nr.find( (void*) p); - if (pos == ptr2nr.end()) - { - ptr2nr[p] = cnt; - int m1 = -1; - (*this) & m1; - cnt++; - (*this) & (*p); - } - else - { - (*this) & pos->second; - } - } - else - { - int nr; - (*this) & nr; - cout << "in, got nr " << nr << endl; - if (nr == -2) - { - p = nullptr; - } - else if (nr == -1) - { - p = new T; - cout << "create new ptr, p = " << p << endl; - (*this) & *p; - nr2ptr.push_back(p); - } - else - { - p = (T*)nr2ptr[nr]; - cout << "reuse ptr " << nr << ": " << p << endl; - } - } - return *this; - } - - - - template - Archive & operator << (const T & t) - { - T ht(t); - (*this) & ht; - return *this; - } - }; - - -} - - -#endif diff -Nru ngsolve-6.2.1810/ngstd/archive.cpp ngsolve-6.2.1901/ngstd/archive.cpp --- ngsolve-6.2.1810/ngstd/archive.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/archive.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,375 +0,0 @@ -/**************************************************************************/ -/* File: archive.cpp */ -/* Author: Joachim Schoeberl */ -/* Date: 14. Feb. 2014 */ -/**************************************************************************/ - -#include - - -namespace ngstd -{ - - /* ******************* BinaryOutArchive ******************* */ - - - BinaryOutArchive :: BinaryOutArchive (string filename) - : BinaryOutArchive(make_shared(filename.c_str())) - { ; } - - Archive & BinaryOutArchive :: operator & (double & d) - { - return Write(d); - /* - fout->write(reinterpret_cast(&d), sizeof(double)); - return *this; - */ - } - - Archive & BinaryOutArchive :: operator & (int & i) - { - return Write(i); - /* - fout->write(reinterpret_cast(&i), sizeof(int)); - return *this; - */ - } - - Archive & BinaryOutArchive :: operator & (short & i) - { - return Write(i); - // fout->write(reinterpret_cast(&i), sizeof(short)); - // return *this; - } - - Archive & BinaryOutArchive :: operator & (long & i) - { - return Write(i); - // fout->write(reinterpret_cast(&i), sizeof(long)); - // return *this; - } - - Archive & BinaryOutArchive :: operator & (size_t & i) - { - return Write(i); - // fout->write(reinterpret_cast(&i), sizeof(size_t)); - // return *this; - } - - Archive & BinaryOutArchive :: operator & (unsigned char & i) - { - return Write(i); - // fout->write(reinterpret_cast(&i), sizeof(unsigned char)); - // return *this; - } - - Archive & BinaryOutArchive :: operator & (bool & b) - { - return Write(b); - // fout->write(reinterpret_cast(&b), sizeof(bool)); - // return *this; - } - - Archive & BinaryOutArchive :: operator & (string & str) - { - if (ptr > 0) FlushBuffer(); - - int len = str.length(); - fout->write (reinterpret_cast(&len), sizeof(int)); - fout->write (&str[0], len); - return *this; - } - - Archive & BinaryOutArchive :: operator & (char *& str) - { - if (ptr > 0) FlushBuffer(); - - int len = strlen (str); - fout->write (reinterpret_cast(&len), sizeof(int)); - fout->write (&str[0], len); - return *this; - } - - - template - Archive & BinaryOutArchive :: Write (T x) - { - if (unlikely(ptr > BUFFERSIZE-sizeof(T))) - { - fout->write(&buffer[0], ptr); - * (T*) (&buffer[0]) = x; - ptr = sizeof(T); - return *this; - } - * (T*) (&buffer[ptr]) = x; - ptr += sizeof(T); - return *this; - /* - fout->write(reinterpret_cast(&x), sizeof(T)); - return *this; - */ - } - - void BinaryOutArchive :: FlushBuffer() - { - if (ptr > 0) - { - fout->write(&buffer[0], ptr); - ptr = 0; - } - } - - - - /* ******************* BinaryInArchive ******************* */ - - - BinaryInArchive :: BinaryInArchive (string filename) - : BinaryInArchive(make_shared(filename.c_str())) { ; } - // { fin = make_shared(filename.c_str()); } - - Archive & BinaryInArchive :: operator & (double & d) - { - fin->read(reinterpret_cast(&d), sizeof(double)); - return *this; - } - - Archive & BinaryInArchive :: operator & (int & i) - { - fin->read(reinterpret_cast(&i), sizeof(int)); - return *this; - } - - Archive & BinaryInArchive :: operator & (short & i) - { - fin->read(reinterpret_cast(&i), sizeof(short)); - return *this; - } - - Archive & BinaryInArchive :: operator & (long & i) - { - fin->read(reinterpret_cast(&i), sizeof(long)); - return *this; - } - - Archive & BinaryInArchive :: operator & (size_t & i) - { - fin->read(reinterpret_cast(&i), sizeof(size_t)); - return *this; - } - - Archive & BinaryInArchive :: operator & (unsigned char & i) - { - fin->read(reinterpret_cast(&i), sizeof(unsigned char)); - return *this; - } - - Archive & BinaryInArchive :: operator & (bool & b) - { - fin->read(reinterpret_cast(&b), sizeof(bool)); - return *this; - } - - Archive & BinaryInArchive :: operator & (string & str) - { - int len; - fin->read(reinterpret_cast(&len), sizeof(int)); - str.resize(len); - fin->read(&str[0], len); - return *this; - } - - Archive & BinaryInArchive :: operator & (char *& str) - { - int len; - fin->read(reinterpret_cast(&len), sizeof(int)); - str = new char[len+1]; - fin->read(&str[0], len); - str[len] = '\0'; - return *this; - } - - - Archive & BinaryInArchive :: Do (double * d, size_t n) - { - cout << "load double array, size = " << n << endl; - fin->read(reinterpret_cast(d), n*sizeof(double)); - return *this; - } - - Archive & BinaryInArchive :: Do (int * i, size_t n) - { - cout << "load int array, size = " << n << endl; - fin->read(reinterpret_cast(i), n*sizeof(int)); - return *this; - } - - Archive & BinaryInArchive :: Do (size_t * i, size_t n) - { - cout << "load size_t array, size = " << n << endl; - fin->read(reinterpret_cast(i), n*sizeof(size_t)); - return *this; - } - - - - - - - - - - - /* ******************* TextOutArchive ******************* */ - - - TextOutArchive :: TextOutArchive (string filename) - : TextOutArchive(make_shared(filename.c_str())) { ; } - - - Archive & TextOutArchive :: operator & (double & d) - { - *fout << d << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (int & i) - { - *fout << i << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (short & i) - { - *fout << i << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (long & i) - { - *fout << i << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (size_t & i) - { - *fout << i << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (unsigned char & i) - { - *fout << int (i) << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (bool & b) - { - *fout << (b ? 't' : 'f') << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (string & str) - { - int len = str.length(); - *fout << len << '\n'; - fout->write (&str[0], len); - *fout << '\n'; - return *this; - } - - Archive & TextOutArchive :: operator & (char *& str) - { - int len = strlen (str); - *fout << len << '\n'; - fout->write (&str[0], len); - *fout << '\n'; - return *this; - } - - - - - - /* ******************* TextInArchive ******************* */ - - - TextInArchive :: TextInArchive (string filename) - : TextInArchive(make_shared(filename.c_str())) { ; } - - - Archive & TextInArchive :: operator & (double & d) - { - *fin >> d; - return *this; - } - - Archive & TextInArchive :: operator & (int & i) - { - *fin >> i; - return *this; - } - - Archive & TextInArchive :: operator & (short & i) - { - *fin >> i; - return *this; - } - - Archive & TextInArchive :: operator & (long & i) - { - *fin >> i; - return *this; - } - - Archive & TextInArchive :: operator & (size_t & i) - { - *fin >> i; - return *this; - } - - Archive & TextInArchive :: operator & (unsigned char & i) - { - int hi; - *fin >> hi; - i = hi; - return *this; - } - - Archive & TextInArchive :: operator & (bool & b) - { - char c; - *fin >> c; - b = (c == 't'); - return *this; - } - - Archive & TextInArchive :: operator & (string & str) - { - int len; - *fin >> len; - - char ch; - fin->get(ch); // '\n' - - str.resize(len); - fin->get(&str[0], len+1, '\0'); - return *this; - } - - Archive & TextInArchive :: operator & (char *& str) - { - int len; - *fin >> len; - - char ch; - fin->get(ch); // '\n' - - str = new char[len+1]; - fin->get(&str[0], len, '\0'); - str[len] = 0; - return *this; - } - - -} diff -Nru ngsolve-6.2.1810/ngstd/archive.hpp ngsolve-6.2.1901/ngstd/archive.hpp --- ngsolve-6.2.1810/ngstd/archive.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/archive.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,173 +0,0 @@ -#ifndef FILE_ARCHIVE -#define FILE_ARCHIVE - - -#include "archive_base.hpp" - - -namespace ngstd -{ - class TextOutArchive : public Archive - { - shared_ptr fout; - public: - TextOutArchive (string filename); - TextOutArchive (shared_ptr afout) : Archive(true), fout(afout) { ; } - - // virtual bool Output (); - // virtual bool Input (); - using Archive::operator&; - virtual Archive & operator & (double & d); - virtual Archive & operator & (int & i); - virtual Archive & operator & (short & i); - virtual Archive & operator & (long & i); - virtual Archive & operator & (size_t & i); - virtual Archive & operator & (unsigned char & i); - virtual Archive & operator & (bool & b); - virtual Archive & operator & (string & str); - virtual Archive & operator & (char *& str); - }; - - - class TextInArchive : public Archive - { - shared_ptr fin; - public: - TextInArchive (string filename); - TextInArchive (shared_ptr afin) : Archive(false), fin(afin) { ; } - - // virtual bool Output (); - // virtual bool Input (); - using Archive::operator&; - virtual Archive & operator & (double & d); - virtual Archive & operator & (int & i); - virtual Archive & operator & (short & i); - virtual Archive & operator & (long & i); - virtual Archive & operator & (size_t & i); - virtual Archive & operator & (unsigned char & i); - virtual Archive & operator & (bool & b); - virtual Archive & operator & (string & str); - virtual Archive & operator & (char *& str); - }; - - - class BinaryOutArchive : public Archive - { - shared_ptr fout; - size_t ptr = 0; - enum { BUFFERSIZE = 1024 }; - char buffer[BUFFERSIZE]; - public: - BinaryOutArchive (string filename); - BinaryOutArchive (shared_ptr afout) : Archive(true), fout(afout) { ; } - virtual ~BinaryOutArchive () { FlushBuffer(); } - // virtual bool Output (); - // virtual bool Input (); - - virtual Archive & operator & (double & d); - virtual Archive & operator & (int & i); - virtual Archive & operator & (short & i); - virtual Archive & operator & (long & i); - virtual Archive & operator & (size_t & i); - virtual Archive & operator & (unsigned char & i); - virtual Archive & operator & (bool & b); - virtual Archive & operator & (string & str); - virtual Archive & operator & (char *& str); - - template - Archive & Write (T x); - void FlushBuffer(); - }; - - - class BinaryInArchive : public Archive - { - shared_ptr fin; - public: - BinaryInArchive (string filename); - BinaryInArchive (shared_ptr afin) : Archive(false), fin(afin) { ; } - - // virtual bool Output (); - // virtual bool Input (); - - virtual Archive & operator & (double & d); - virtual Archive & operator & (int & i); - virtual Archive & operator & (short & i); - virtual Archive & operator & (long & i); - virtual Archive & operator & (size_t & i); - virtual Archive & operator & (unsigned char & i); - virtual Archive & operator & (bool & b); - virtual Archive & operator & (string & str); - virtual Archive & operator & (char *& str); - - virtual Archive & Do (double * d, size_t n); - virtual Archive & Do (int * i, size_t n); - virtual Archive & Do (size_t * i, size_t n); - - }; - - - - - - - - - - /* - // archive a pointer ... - template - Archive & operator& (Archive & ar, T *& p) - { - if (ar.Output()) - ar & (*p); - else - { - p = new T; - ar & *p; - } - return ar; - } - */ - - - // archive a shared pointer ... - template - Archive & operator& (Archive & ar, shared_ptr & p) - { - if (ar.Output()) - ar & (*p); - else - { - p = make_shared(); - ar & *p; - } - return ar; - } - - - /* - // cannot archive type T - template - Archive & operator& (Archive & ar, T & t) - { - if (ar.Output()) - { - cout << string("Cannot_archive_object_of_type ") << string(typeid(T).name()) << endl; - ar << string("Cannot_archive_object_of_type ") << string(typeid(T).name()); - } - else - { - string dummy; - ar & dummy; - ar & dummy; - } - return ar; - } - */ -} - - - - -#endif diff -Nru ngsolve-6.2.1810/ngstd/array.hpp ngsolve-6.2.1901/ngstd/array.hpp --- ngsolve-6.2.1810/ngstd/array.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/array.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -679,6 +679,21 @@ delete [] mem_to_delete; } + // Only provide this function if T is archivable + template + auto DoArchive(Archive& archive) -> typename std::enable_if_t, void> + { + if(archive.Output()) + archive << size; + else + { + size_t s; + archive & s; + SetSize(s); + } + archive.Do(data, size); + } + /// we tell the compiler that there is no need for deleting the array .. INLINE void NothingToDelete () { @@ -1411,27 +1426,6 @@ { return ar.Ptr()+i; } - - - template - Archive & operator & (Archive & archive, Array & a) - { - if (archive.Output()) - archive << a.Size(); - else - { - size_t size; - archive & size; - a.SetSize (size); - } - - /* - for (auto & ai : a) - archive & ai; - */ - archive.Do (&a[0], a.Size()); - return archive; - } } diff -Nru ngsolve-6.2.1810/ngstd/autodiffdiff.hpp ngsolve-6.2.1901/ngstd/autodiffdiff.hpp --- ngsolve-6.2.1810/ngstd/autodiffdiff.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/autodiffdiff.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -452,12 +452,12 @@ AutoDiffDiff res; res.Value() = sqrt(x.Value()); for (int j = 0; j < D; j++) - res.DValue(j) = 0.5 / res.Value() * x.DValue(j); + res.DValue(j) = IfZero(x.DValue(j),0.,0.5 / res.Value() * x.DValue(j)); for (int i = 0; i < D; i++) for (int j = 0; j < D; j++) - res.DDValue(i,j) = 0.5/res.Value() * x.DDValue(i,j) - 0.25 / (x.Value()*res.Value()) * x.DValue(i) * x.DValue(j); + res.DDValue(i,j) = IfZero(x.DDValue(i,j)+x.DValue(i) * x.DValue(j),0.,0.5/res.Value() * x.DDValue(i,j) - 0.25 / (x.Value()*res.Value()) * x.DValue(i) * x.DValue(j)); return res; } diff -Nru ngsolve-6.2.1810/ngstd/CMakeLists.txt ngsolve-6.2.1901/ngstd/CMakeLists.txt --- ngsolve-6.2.1810/ngstd/CMakeLists.txt 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/CMakeLists.txt 2019-01-12 00:18:33.000000000 +0000 @@ -3,7 +3,7 @@ set(ngstd_sources exception.cpp table.cpp bitarray.cpp flags.cpp symboltable.cpp blockalloc.cpp evalfunc.cpp templates.cpp - localheap.cpp stringops.cpp profiler.cpp archive.cpp + localheap.cpp stringops.cpp profiler.cpp cuda_ngstd.cpp python_ngstd.cpp taskmanager.cpp paje_interface.cpp bspline.cpp ) @@ -32,7 +32,7 @@ flags.hpp hashtable.hpp localheap.hpp memusage.hpp ngstd.hpp profiler.hpp stringops.hpp symboltable.hpp table.hpp templates.hpp parthreads.hpp statushandler.hpp ngsstream.hpp mpiwrapper.hpp - polorder.hpp archive.hpp archive_base.hpp sockets.hpp cuda_ngstd.hpp + polorder.hpp sockets.hpp cuda_ngstd.hpp mycomplex.hpp tuple.hpp paje_interface.hpp python_ngstd.hpp ngs_utils.hpp taskmanager.hpp bspline.hpp xbool.hpp simd.hpp simd_complex.hpp sample_sort.hpp diff -Nru ngsolve-6.2.1810/ngstd/hashtable.hpp ngsolve-6.2.1901/ngstd/hashtable.hpp --- ngsolve-6.2.1810/ngstd/hashtable.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/hashtable.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -69,6 +69,11 @@ INLINE INT (T ai1, T ai2, T ai3, T ai4, T ai5, T ai6, T ai7, T ai8, T ai9) { i[0] = ai1; i[1] = ai2; i[2] = ai3; i[3] = ai4; i[4] = ai5; i[5] = ai6; i[6] = ai7; i[7] = ai8; i[8] = ai9; } + void DoArchive(Archive& ar) + { + ar.Do(i, N); + } + template INLINE INT (const INT & in2) { diff -Nru ngsolve-6.2.1810/ngstd/ngstd.hpp ngsolve-6.2.1901/ngstd/ngstd.hpp --- ngsolve-6.2.1810/ngstd/ngstd.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/ngstd.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -128,9 +128,10 @@ #include // #include "mycomplex.hpp" +#include +namespace ngstd { using namespace ngcore; } #include "ngs_utils.hpp" -#include "archive_base.hpp" #include "ngsstream.hpp" #include "templates.hpp" #include "exception.hpp" @@ -168,7 +169,6 @@ #ifndef WIN32 #include "sockets.hpp" #endif -#include "archive.hpp" namespace ngstd { diff -Nru ngsolve-6.2.1810/ngstd/ngs_utils.hpp ngsolve-6.2.1901/ngstd/ngs_utils.hpp --- ngsolve-6.2.1810/ngstd/ngs_utils.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/ngs_utils.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -191,15 +191,7 @@ ~MyLock () { mutex.unlock(); } }; - -#if defined(__GNUC__) - inline bool likely (bool x) { return __builtin_expect((x), true); } - inline bool unlikely (bool x) { return __builtin_expect((x), false); } -#else - inline bool likely (bool x) { return x; } - inline bool unlikely (bool x) { return x; } -#endif - + diff -Nru ngsolve-6.2.1810/ngstd/python_ngstd.hpp ngsolve-6.2.1901/ngstd/python_ngstd.hpp --- ngsolve-6.2.1810/ngstd/python_ngstd.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/python_ngstd.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -358,6 +358,24 @@ throw py::type_error("Cannot convert Python object to C Array"); } +template +Table makeCTable (py::list obj) +{ + size_t n = py::len(obj); + Array entrysize(n); + + for (size_t i = 0; i < n; i++) + entrysize[i] = py::len(obj[i]); + + Table tab(entrysize); + for (size_t i = 0; i < n; i++) + { + const py::object & obji = obj[i]; + tab[i] = makeCArray (obji); + } + return tab; +} + template Array makeCArraySharedPtr(const py::list & obj) { @@ -489,8 +507,12 @@ { py::list list; public: - PyOutArchive () : Archive(true) { ; } + PyOutArchive () : Archive(true) { } py::list GetList() const { return list; } + const VersionInfo& GetVersion(const std::string& library) + { return GetLibraryVersions()[library]; } + + using Archive::operator&; virtual Archive & operator & (double & d) { list.append(py::cast(d)); return *this; } virtual Archive & operator & (int & i) { list.append(py::cast(i)); return *this; } virtual Archive & operator & (short & i) { list.append(py::cast(i)); return *this; } @@ -509,8 +531,12 @@ // decltype(list.begin())auto iter; size_t iter; public: - PyInArchive (py::list alist) : Archive(false), list(alist), iter(0) { ; } + PyInArchive (py::list alist) : Archive(false), list(alist), iter(0) + { + } + const VersionInfo& GetVersion(const std::string& library) { return GetLibraryVersions()[library]; } + using Archive::operator&; virtual Archive & operator & (double & d) { d = py::cast (list[iter]); iter++; return *this; } virtual Archive & operator & (int & d) { d = py::cast (list[iter]); iter++; return *this; } virtual Archive & operator & (short & d) { d = py::cast (list[iter]); iter++; return *this; } diff -Nru ngsolve-6.2.1810/ngstd/simd.hpp ngsolve-6.2.1901/ngstd/simd.hpp --- ngsolve-6.2.1810/ngstd/simd.hpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/ngstd/simd.hpp 2019-01-12 00:18:33.000000000 +0000 @@ -617,6 +617,7 @@ INLINE double IfPos (double a, double b, double c) { return a>0 ? b : c; } + INLINE double IfZero (double a, double b, double c) { return a==0. ? b : c; } #ifdef __SSE__ @@ -639,6 +640,8 @@ { return ngstd::SIMD([&](int i)->double { return ceil(a[i]); } ); } INLINE SIMD IfPos (SIMD a, SIMD b, SIMD c) { return ngstd::SIMD([&](int i)->double { return a[i]>0 ? b[i] : c[i]; }); } + INLINE SIMD IfZero (SIMD a, SIMD b, SIMD c) + { return ngstd::SIMD([&](int i)->double { return a[i]==0. ? b[i] : c[i]; }); } INLINE double HSum (SIMD sd) @@ -673,6 +676,12 @@ return _mm256_blendv_pd(c.Data(), b.Data(), cp); } + INLINE SIMD IfZero (SIMD a, SIMD b, SIMD c) + { + auto cp = _mm256_cmp_pd (a.Data(), _mm256_setzero_pd(), _CMP_EQ_OS); + return _mm256_blendv_pd(c.Data(), b.Data(), cp); + } + INLINE double HSum (SIMD sd) { // __m128d hv = _mm_add_pd (_mm256_extractf128_pd(sd.Data(),0), _mm256_extractf128_pd(sd.Data(),1)); @@ -710,6 +719,11 @@ auto k = _mm512_cmp_pd_mask(a.Data(),_mm512_setzero_pd(), _CMP_GT_OS); return _mm512_mask_blend_pd(k,c.Data(),b.Data()); } + INLINE SIMD IfZero (SIMD a, SIMD b, SIMD c) + { + auto k = _mm512_cmp_pd_mask(a.Data(),_mm512_setzero_pd(), _CMP_EQ_OS); + return _mm512_mask_blend_pd(k,c.Data(),b.Data()); + } INLINE auto Unpack (SIMD a, SIMD b) @@ -789,6 +803,10 @@ { return (a.Data() > 0) ? b : c; } + INLINE SIMD IfZero (SIMD a, SIMD b, SIMD c) + { + return (a.Data() == 0.) ? b : c; + } INLINE double HSum (SIMD sd) { return sd.Data(); } diff -Nru ngsolve-6.2.1810/python/bvp.py ngsolve-6.2.1901/python/bvp.py --- ngsolve-6.2.1810/python/bvp.py 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/python/bvp.py 2019-01-12 00:18:33.000000000 +0000 @@ -1,9 +1,9 @@ -from ngsolve import Projector, solvers - def BVP(bf, lf, gf, pre=None, maxsteps=200, tol=1e-8, print=True, inverse="umfpack"): """ Solve a linear boundary value problem """ + from ngsolve import Projector + from ngsolve.krylovspace import CG r = lf.vec.CreateVector() r.data = lf.vec @@ -16,7 +16,7 @@ Projector(innerbits, False).Project(gf.vec) if pre: - solvers.CG(mat = bf.mat, rhs = r, pre=pre.mat, sol=gf.vec, tol=tol, initialize=False, printrates=print) + CG(mat = bf.mat, rhs = r, pre=pre, sol=gf.vec, tol=tol, initialize=False, printrates=print) else: inv = bf.mat.Inverse(gf.space.FreeDofs(bf.condense), inverse=inverse) r.data -= bf.mat * gf.vec diff -Nru ngsolve-6.2.1810/python/__init__.py ngsolve-6.2.1901/python/__init__.py --- ngsolve-6.2.1810/python/__init__.py 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/python/__init__.py 2019-01-12 00:18:33.000000000 +0000 @@ -32,8 +32,8 @@ ngstd.__all__ = ['ArrayD', 'ArrayI', 'BitArray', 'Flags', 'HeapReset', 'IntRange', 'LocalHeap', 'Timers', 'RunWithTaskManager', 'TaskManager', 'SetNumThreads', 'MPI_Init'] bla.__all__ = ['Matrix', 'Vector', 'InnerProduct', 'Norm'] -la.__all__ = ['BaseMatrix', 'BaseVector', 'BlockVector', 'BlockMatrix', 'CreateVVector', 'InnerProduct', 'CGSolver', 'QMRSolver', 'GMRESSolver', 'ArnoldiSolver', 'Projector', 'IdentityMatrix', 'Embedding'] -fem.__all__ = ['BFI', 'CoefficientFunction', 'Parameter', 'CoordCF', 'ET', 'ElementTransformation', 'ElementTopology', 'FiniteElement', 'ScalarFE', 'H1FE', 'HEX', 'L2FE', 'LFI', 'POINT', 'PRISM', 'PYRAMID', 'QUAD', 'SEGM', 'TET', 'TRIG', 'VERTEX', 'EDGE', 'FACE', 'CELL', 'ELEMENT', 'FACET', 'SetPMLParameters', 'sin', 'cos', 'tan', 'atan', 'acos', 'asin', 'exp', 'log', 'sqrt', 'floor', 'ceil', 'Conj', 'atan2', 'pow', 'specialcf', \ +la.__all__ = ['BaseMatrix', 'BaseVector', 'BlockVector', 'BlockMatrix', 'CreateVVector', 'InnerProduct', 'CGSolver', 'QMRSolver', 'GMRESSolver', 'ArnoldiSolver', 'Projector', 'IdentityMatrix', 'Embedding', 'ConstEBEMatrix'] +fem.__all__ = ['BFI', 'CoefficientFunction', 'Parameter', 'CoordCF', 'ET', 'ElementTransformation', 'ElementTopology', 'FiniteElement', 'MixedFE', 'ScalarFE', 'H1FE', 'HEX', 'L2FE', 'LFI', 'POINT', 'PRISM', 'PYRAMID', 'QUAD', 'SEGM', 'TET', 'TRIG', 'VERTEX', 'EDGE', 'FACE', 'CELL', 'ELEMENT', 'FACET', 'SetPMLParameters', 'sin', 'cos', 'tan', 'atan', 'acos', 'asin', 'exp', 'log', 'sqrt', 'floor', 'ceil', 'Conj', 'atan2', 'pow', 'specialcf', \ 'BlockBFI', 'BlockLFI', 'CompoundBFI', 'CompoundLFI', 'BSpline', \ 'IntegrationRule', 'IfPos' \ ] diff -Nru ngsolve-6.2.1810/python/meshes.py ngsolve-6.2.1901/python/meshes.py --- ngsolve-6.2.1810/python/meshes.py 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/python/meshes.py 2019-01-12 00:18:33.000000000 +0000 @@ -4,7 +4,24 @@ def Make1DMesh(n, mapping = None, periodic=False): """ - generate an equidistant 1D mesh with N cells + Generate an equidistant 1D mesh with N cells + + Parameters + ---------- + n : int + Number of cells. + + mapping: lamda + Mapping to transform the generated points. If None, the identity mapping is used. + + periodic: bool + If True, the endpoints are identified to generate a periodic mesh. + + Returns + ------- + (ngsolve.mesh) + Returns generated 1D NGSolve mesh + """ mesh = Mesh(dim=1) pids = [] @@ -25,6 +42,36 @@ return ngsmesh def MakeStructured2DMesh(quads=True, nx=10, ny=10, periodic_x=False, periodic_y=False, mapping = None): + """ + Generate a structured 2D mesh + + Parameters + ---------- + quads : bool + If True, a quadrilateral mesh is generated. If False, the quads are split to triangles. + + nx : int + Number of cells in x-direction. + + ny : int + Number of cells in y-direction. + + periodic_x: bool + If True, the left and right boundaries are identified to generate a periodic mesh in x-direction. + + periodic_y: bool + If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction. + + mapping: lamda + Mapping to transform the generated points. If None, the identity mapping is used. + + + Returns + ------- + (ngsolve.mesh) + Returns generated 2D NGSolve mesh + + """ mesh = Mesh() mesh.dim=2 @@ -97,6 +144,33 @@ return ngsmesh def MakeQuadMesh(nx=10, ny=10, periodic_x=False, periodic_y=False, mapping = None): + """ + Generate a structured quadrilateral 2D mesh + + Parameters + ---------- + nx : int + Number of cells in x-direction. + + ny : int + Number of cells in y-direction. + + periodic_x: bool + If True, the left and right boundaries are identified to generate a periodic mesh in x-direction. + + periodic_y: bool + If True, the top and bottom boundaries are identified to generate a periodic mesh in y-direction. + + mapping: lamda + Mapping to transform the generated points. If None, the identity mapping is used. + + + Returns + ------- + (ngsolve.mesh) + Returns generated 2D NGSolve mesh + + """ return MakeStructured2DMesh(quads=True, nx=nx, ny=ny, periodic_x=periodic_x, periodic_y=periodic_y, mapping=mapping) def MakeStructured3DMesh(hexes=True, nx=10, ny=None, nz=None, periodic_x=False, periodic_y=False, periodic_z=False, mapping = None, cuboid_mapping=True): @@ -190,17 +264,17 @@ netmesh.Add(Element3D(1, elpids)) def AddSurfEls(p1, dxi, nxi, deta, neta, facenr): - def add_seg(p1, dxi, deta, i, j): - base = p1 + i*dxi + j*deta - pnum = [base, base+dxi] - elpids = [pids[p] for p in pnum] - netmesh.Add(Element1D(elpids, index=facenr)) + def add_seg(i, j, os): + base = p1 + i*dxi + j*deta + pnum = [base, base+os] + elpids = [pids[p] for p in pnum] + netmesh.Add(Element1D(elpids, index=facenr)) for i in range(nxi): - for j in [0, neta]: - add_seg(i,j) + for j in [0,neta]: + add_seg(i,j,dxi) for i in [0,nxi]: for j in range(neta): - add_seg(i,j) + add_seg(i,j,deta) for i in range(nxi): for j in range(neta): base = p1 + i*dxi+j*deta diff -Nru ngsolve-6.2.1810/solve/ngsolve.cpp ngsolve-6.2.1901/solve/ngsolve.cpp --- ngsolve-6.2.1810/solve/ngsolve.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/solve/ngsolve.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -208,11 +208,12 @@ { Socket & sock; public: - SocketOutArchive (Socket & asock) : Archive(true), sock(asock) { ; } - - virtual bool Output () { return true; } - virtual bool Input () { return false; } + SocketOutArchive (Socket & asock) : Archive(true), sock(asock) + { (*this) & GetLibraryVersions(); } + const VersionInfo& GetVersion(const std::string& library) + { return GetLibraryVersions()[library]; } + using Archive::operator&; virtual Archive & operator & (double & d) { sock.Tsend(d); @@ -263,10 +264,15 @@ class SocketInArchive : public Archive { + std::map vinfo{}; Socket & sock; public: - SocketInArchive (Socket & asock) : Archive(false), sock(asock) { ; } + SocketInArchive (Socket & asock) : Archive(false), sock(asock) + { (*this) & vinfo; } + const VersionInfo& GetVersion(const std::string& library) + { return vinfo[library]; } + using Archive::operator&; virtual Archive & operator & (double & d) { sock.Trecv (d); diff -Nru ngsolve-6.2.1810/solve/python_solve.cpp ngsolve-6.2.1901/solve/python_solve.cpp --- ngsolve-6.2.1810/solve/python_solve.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/solve/python_solve.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -315,7 +315,7 @@ template<> void ExtractRealImag(const double val, int i, float &real, float &imag) { real = val; } template -static void GetValues( const CoefficientFunction &cf, LocalHeap &lh, const TMIR &mir, FlatArray values_real, FlatArray values_imag , FlatArray min, FlatArray max) { +static void GetValues( const CoefficientFunction &cf, LocalHeap &lh, TMIR &mir, FlatArray values_real, FlatArray values_imag , FlatArray min, FlatArray max, bool covariant=false) { static_assert( is_same>::value || is_same>::value || is_same::value || is_same::value, "Unsupported type in GetValues"); HeapReset hr(lh); @@ -323,13 +323,20 @@ auto ncomps = cf.Dimension(); int nip = mir.IR().GetNIP(); auto getIndex = [=] ( int p, int comp ) { return p*ncomps + comp; }; - bool is_complex = is_same>::value || is_same::value; + constexpr bool is_complex = is_same>::value || is_same::value; + constexpr bool is_simd = is_same>::value || is_same>::value; - if(is_same>::value || is_same>::value) + + if constexpr(is_simd) { FlatMatrix values(ncomps, mir.Size(), lh); cf.Evaluate(mir, values); + if constexpr(!is_complex) + if(covariant) { + mir.TransformGradientTrans(values); + } + constexpr int n = SIMD::Size(); for (auto k : Range(nip)) { for (auto i : Range(ncomps)) { @@ -354,6 +361,17 @@ { FlatMatrix values(mir.Size(), ncomps, lh); cf.Evaluate(mir, values); + + if(covariant) { + VectorMem<4,TSCAL> val(ncomps); + for (auto k : Range(nip)) { + val = values.Row(k); + Mat<3,3,double> m = mir[k].GetJacobian(); + CalcInverse(m); + values.Row(k) = m*val; + } + } + for (auto k : Range(nip)) { for (auto i : Range(ncomps)) { float vreal = 0.0; @@ -570,6 +588,7 @@ ElementInformation pyramids[2] = { {ET_PYRAMID}, {ET_PYRAMID, true } }; ElementInformation prisms[2] = { {ET_PRISM}, {ET_PRISM, true } }; ElementInformation hexes[2] = { {ET_HEX}, {ET_HEX, true } }; + Array types_and_numbering; for (auto el : ma->Elements(VOL)) { auto verts = el.Vertices(); @@ -586,6 +605,10 @@ throw Exception("GetMeshData(): unknown element"); } ElementInformation &ei = pei[el.is_curved]; + + types_and_numbering.Append(2*nverts+el.is_curved); + types_and_numbering.Append(ei.nelements); + ei.nelements++; ei.data.Append(el.Nr()); ei.data.Append(el.GetIndex()); @@ -618,6 +641,7 @@ } } } + element_data[VOL].append(types_and_numbering); for (auto i : Range(2)) { if(tets[i].data.Size()) element_data[VOL].append(toDict(tets[i])); if(pyramids[i].data.Size()) element_data[VOL].append(toDict(pyramids[i])); @@ -796,7 +820,7 @@ task_manager=tm; return result; }, py::call_guard()); - m.def("_GetValues", [] (shared_ptr cf, shared_ptr ma, VorB vb, map irs) { + m.def("_GetValues", [] (shared_ptr cf, shared_ptr ma, VorB vb, map irs, bool covariant) { auto tm = task_manager; task_manager = nullptr; LocalHeap lh(10000000, "GetValues"); @@ -855,9 +879,9 @@ { auto & mir = GetMappedIR(ma, el, simd_ir, mlh); if(cf->IsComplex()) - GetValues>( *cf, mlh, mir, vals_real.Range(first,next), vals_imag.Range(first,next), min_local, max_local); + GetValues>( *cf, mlh, mir, vals_real.Range(first,next), vals_imag.Range(first,next), min_local, max_local, covariant); else - GetValues>( *cf, mlh, mir, vals_real.Range(first,next), vals_imag, min_local, max_local); + GetValues>( *cf, mlh, mir, vals_real.Range(first,next), vals_imag, min_local, max_local, covariant); } catch(ExceptionNOSIMD e) { @@ -868,9 +892,9 @@ { auto & mir = GetMappedIR(ma, el, ir, mlh); if(cf->IsComplex()) - GetValues( *cf, mlh, mir, vals_real.Range(first,next), vals_imag.Range(first,next), min_local, max_local); + GetValues( *cf, mlh, mir, vals_real.Range(first,next), vals_imag.Range(first,next), min_local, max_local, covariant); else - GetValues( *cf, mlh, mir, vals_real.Range(first,next), vals_imag, min_local, max_local); + GetValues( *cf, mlh, mir, vals_real.Range(first,next), vals_imag, min_local, max_local, covariant); } for (auto i : Range(ncomps)) { float expected = min[i]; diff -Nru ngsolve-6.2.1810/tests/catch/ngblas.cpp ngsolve-6.2.1901/tests/catch/ngblas.cpp --- ngsolve-6.2.1810/tests/catch/ngblas.cpp 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/tests/catch/ngblas.cpp 2019-01-12 00:18:33.000000000 +0000 @@ -250,6 +250,33 @@ } } } + + // IfPos etc. not implemented for SIMD<4> on non-AVX builds + if constexpr(N <= SIMD::Size()) { + SECTION ("IfPos") { + dst[0] = 1; + for (auto i : Range(1,N)) { + dst[i] = -dst[i-1]; + } + SIMD srcsimd(src); + SIMD simd = IfPos(dst, srcsimd,-srcsimd); + for (auto i : Range(N)) { + CHECK(simd[i] == ( i%2 ? -srcsimd[i] : srcsimd[i] )); + } + } + + SECTION ("IfZero") { + for (auto i : Range(N)) { + dst[i] = i%2; + } + SIMD srcsimd(src); + SIMD simd = IfZero(dst, srcsimd,-srcsimd); + for (auto i : Range(N)) { + CHECK(simd[i] == ( i%2 ? -srcsimd[i] : srcsimd[i] )); + } + } + } + } TEST_CASE ("SIMD", "[simd]") { TestSIMD<>(); } diff -Nru ngsolve-6.2.1810/tests/gitlab-ci/ubuntu/cleanup.sh ngsolve-6.2.1901/tests/gitlab-ci/ubuntu/cleanup.sh --- ngsolve-6.2.1810/tests/gitlab-ci/ubuntu/cleanup.sh 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/tests/gitlab-ci/ubuntu/cleanup.sh 2019-01-12 00:18:33.000000000 +0000 @@ -2,7 +2,7 @@ docker ps -a | awk '{ print $1,$2 }' | grep ngsolve_${CI_PIPELINE_ID} | awk '{print $1 }' | xargs -I {} docker rm {} || true ## list of images to delete -declare -a arr=("16.04" "16.10" "17.04" "17.10" "debug" "avx" "avx512") +declare -a arr=("16.04" "16.10" "17.04" "17.10" "debug" "avx" "avx512" "latest" "mpi") for version in "${arr[@]}" do diff -Nru ngsolve-6.2.1810/tests/gitlab-ci/ubuntu/docker_template ngsolve-6.2.1901/tests/gitlab-ci/ubuntu/docker_template --- ngsolve-6.2.1810/tests/gitlab-ci/ubuntu/docker_template 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/tests/gitlab-ci/ubuntu/docker_template 2019-01-12 00:18:33.000000000 +0000 @@ -3,9 +3,9 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get -y upgrade RUN apt-get update && apt-get -y install libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache openssh-client -RUN apt-get update && apt-get -y install python3 libpython3-dev python3-pytest python3-numpy python3-sphinx python3-pip +RUN apt-get update && apt-get -y install python3 libpython3-dev python3-pytest python3-numpy python3-pip RUN apt-get update && apt-get -y install liboce-ocaf-dev libsuitesparse-dev python3-tk pandoc zip -RUN pip3 install sphinx_rtd_theme ipython nbsphinx jupyter-client nbstripout +RUN pip3 install sphinx sphinx_rtd_theme ipython nbsphinx jupyter-client nbstripout ENV PATH="/opt/netgen/bin:${PATH}" ADD . /root/src/ngsolve diff -Nru ngsolve-6.2.1810/tests/pytest/test_compound_fes.py ngsolve-6.2.1901/tests/pytest/test_compound_fes.py --- ngsolve-6.2.1810/tests/pytest/test_compound_fes.py 2018-11-29 09:47:47.000000000 +0000 +++ ngsolve-6.2.1901/tests/pytest/test_compound_fes.py 2019-01-12 00:18:33.000000000 +0000 @@ -29,3 +29,28 @@ assert Norm(m.AsVector())/fes.ndof<1e-15 +# check if component gf keeps gf alive +def test_component_keeps_alive(): + mesh = Mesh(unit_square.GenerateMesh(maxh=2)) + assert mesh.ne == 2 + fes1 = H1(mesh) + fes = FESpace([fes1,fes1]) + gf = GridFunction(fes) + gf.vec[:] = 1 + gf1, gf2 = gf.components + assert len(gf.vec) == 8 + assert len(gf1.vec) == 4 + mesh.Refine() + gf.Update() + # check if gf update calls gf1 update as well + assert len(gf.vec) == 18 + assert len(gf1.vec) == 9 + del gf + # check if vec is still alive + assert len(gf1.vec) == 9 + gf1.Set(0) + for val in gf1.vec: + assert val == 0.0 + +if __name__ == "__main__": + test_component_keeps_alive() diff -Nru ngsolve-6.2.1810/version.txt ngsolve-6.2.1901/version.txt --- ngsolve-6.2.1810/version.txt 2018-11-29 09:49:11.000000000 +0000 +++ ngsolve-6.2.1901/version.txt 2019-01-12 00:20:04.000000000 +0000 @@ -1 +1 @@ -v6.2.1810-0-g5a872d38 +v6.2.1901-0-ga31a905c