[Getfem-commits] (no subject)
branch: comparing_stored_objects_by_key commit 7085b857a93d0f58d6973402a3a2c482880f83b6 Author: aa Date: Tue Jul 31 03:40:59 2018 +0200 two more overloads for equal --- src/bgeot_convex_ref.cc | 29 +++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/bgeot_convex_ref.cc b/src/bgeot_convex_ref.cc index cc3dc59..e7b7c5e 100644 --- a/src/bgeot_convex_ref.cc +++ b/src/bgeot_convex_ref.cc @@ -150,7 +150,7 @@ namespace bgeot { struct stored_point_tab_key : virtual public dal::static_stored_object_key { const stored_point_tab *pspt; -virtual bool compare(const static_stored_object_key ) const { +bool compare(const static_stored_object_key ) const override { const stored_point_tab_key = dynamic_cast(oo); const stored_point_tab = *pspt; @@ -169,6 +169,23 @@ namespace bgeot { if (it2 != y.end()) return true; return false; } +bool equal(const static_stored_object_key ) const override { + auto = dynamic_cast(oo); + auto = *pspt; + auto = *(o.pspt); + if ( == ) return true; + if (x.size() != y.size()) return false; + auto it1 = x.begin(); + auto it2 = y.begin(); + base_node::const_iterator itn1, itn2, itne; + for ( ; it1 != x.end() && it2 != y.end() ; ++it1, ++it2) { +if ((*it1).size() != (*it2).size()) return false; +itn1 = (*it1).begin(); itne = (*it1).end(); itn2 = (*it2).begin(); +for ( ; itn1 != itne ; ++itn1, ++itn2) + if (*itn1 != *itn2) return false; + } + return true; +} stored_point_tab_key(const stored_point_tab *p) : pspt(p) {} }; @@ -216,7 +233,7 @@ namespace bgeot { // 2 = dummy dim_type N; short_type K; short_type nf; public : -virtual bool compare(const static_stored_object_key ) const { +bool compare(const static_stored_object_key ) const override{ const convex_of_reference_key = dynamic_cast(oo); if (type < o.type) return true; @@ -228,6 +245,14 @@ namespace bgeot { if (nf < o.nf) return true; return false; } +bool equal(const static_stored_object_key ) const override{ + auto = dynamic_cast(oo); + if (type != o.type) return false; + if (N != o.N) return false; + if (K != o.K) return false; + if (nf != o.nf) return false; + return true; +} convex_of_reference_key(int t, dim_type NN, short_type KK = 0, short_type nnf = 0) : type(t), N(NN), K(KK), nf(nnf) {}
[Getfem-commits] (no subject)
branch: comparing_stored_objects_by_key commit 012f127cb5e159d0e03ff4195fb70b85c40417a9 Author: aa Date: Tue Jul 31 00:19:06 2018 +0200 - search_stored_object_on_all_threads - equal method for static keys --- src/dal_static_stored_objects.cc | 20 src/getfem/dal_static_stored_objects.h | 29 + 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/dal_static_stored_objects.cc b/src/dal_static_stored_objects.cc index 67445b0..fef41c6 100644 --- a/src/dal_static_stored_objects.cc +++ b/src/dal_static_stored_objects.cc @@ -191,6 +191,26 @@ static bool dal_static_stored_tab_valid__ = true; return 0; } + pstatic_stored_object search_stored_object_on_all_threads(pstatic_stored_object_key k) + { +auto& stored_objects = singleton::instance(); +if (dal_static_stored_tab_valid__) { + auto p = stored_objects.search_stored_object(k); + if (p) return p; + else if (num_threads() > 1){ +for(size_t thread = 0; thread < getfem::num_threads(); thread++) +{ + if (thread == this_thread()) continue; + auto& other_objects = singleton::instance(thread); + p = other_objects.search_stored_object(k); + if (p) return p; +} + } + return nullptr; +} +return nullptr; + } + std::pair iterators_of_object( pstatic_stored_object o) { diff --git a/src/getfem/dal_static_stored_objects.h b/src/getfem/dal_static_stored_objects.h index f8acb95..ce5b547 100644 --- a/src/getfem/dal_static_stored_objects.h +++ b/src/getfem/dal_static_stored_objects.h @@ -127,9 +127,8 @@ namespace dal { class static_stored_object_key { protected : -virtual bool compare(const static_stored_object_key &) const { - GMM_ASSERT1(false, "This method should not be called"); -} +virtual bool compare(const static_stored_object_key &) const = 0; +virtual bool equal(const static_stored_object_key &) const = 0; public : bool operator < (const static_stored_object_key ) const { @@ -139,18 +138,30 @@ namespace dal { return compare(o); } -virtual ~static_stored_object_key() {} +bool operator == (const static_stored_object_key ) const { + if (typeid(o)!=typeid(*this)) return false; + return equal(o); +} - }; +bool operator != (const static_stored_object_key ) const { + return !(*this == o); +} +virtual ~static_stored_object_key() {} + }; template class simple_key : virtual public static_stored_object_key { var_type a; public : -virtual bool compare(const static_stored_object_key ) const { - const simple_key = dynamic_cast(oo); - return (a < o.a); + bool compare(const static_stored_object_key ) const override { + auto = dynamic_cast(oo); + return a < o.a; +} + +bool equal(const static_stored_object_key ) const override { + auto = dynamic_cast(oo); + return a == o.a; } simple_key(var_type aa) : a(aa) {} }; @@ -208,6 +219,8 @@ namespace dal { /** Gives a pointer to an object from a key pointer. */ pstatic_stored_object search_stored_object(pstatic_stored_object_key k); + pstatic_stored_object search_stored_object_on_all_threads(pstatic_stored_object_key k); + /** Test if an object is stored*/ bool exists_stored_object(pstatic_stored_object o);
[Getfem-commits] (no subject)
branch: comparing_stored_objects_by_key commit 79fb7ae312a6ebf4e954d1bf54e5f3747f74ff14 Author: aa Date: Tue Jul 31 00:20:02 2018 +0200 overriding equal for method_key --- src/getfem/dal_naming_system.h | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/getfem/dal_naming_system.h b/src/getfem/dal_naming_system.h index 71f1226..9c66eb5 100644 --- a/src/getfem/dal_naming_system.h +++ b/src/getfem/dal_naming_system.h @@ -89,9 +89,13 @@ namespace dal { struct method_key : virtual public static_stored_object_key { std::string name; - virtual bool compare(const static_stored_object_key ) const { - const method_key = dynamic_cast(oo); - if (name < o.name) return true; else return false; + bool compare(const static_stored_object_key ) const override{ +auto = dynamic_cast(oo); +return name < o.name; + } + bool equal(const static_stored_object_key ) const override{ +auto = dynamic_cast(oo); +return name == o.name; } method_key(const std::string _) : name(name_) {} };
[Getfem-commits] (no subject)
branch: comparing_stored_objects_by_key commit e8a34a7b1912a64cbbe1187d08c522c4ba62f040 Author: aa Date: Tue Jul 31 00:30:28 2018 +0200 override equal for special_convex_structure_key_ --- src/getfem/bgeot_convex.h | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/getfem/bgeot_convex.h b/src/getfem/bgeot_convex.h index 6021f38..58adc3c 100644 --- a/src/getfem/bgeot_convex.h +++ b/src/getfem/bgeot_convex.h @@ -184,12 +184,21 @@ namespace bgeot { struct special_convex_structure_key_ : virtual public dal::static_stored_object_key { pconvex_structure p; -virtual bool compare(const static_stored_object_key ) const { - const special_convex_structure_key_ -= dynamic_cast(oo); +bool compare(const static_stored_object_key ) const override { + auto = dynamic_cast(oo); if (p < o.p) return true; return false; } +bool equal(const static_stored_object_key ) const override { + auto = dynamic_cast(oo); + if (p == o.p) return true; + + auto pkey = dal::key_of_stored_object(p); + auto poo_key = dal::key_of_stored_object(o.p); + if (*pkey != *poo_key) return false; + + return true; +} special_convex_structure_key_(pconvex_structure pp) : p(pp) {} };
[Getfem-commits] (no subject)
branch: comparing_stored_objects_by_key commit 7e0a80acd34c4a79ccaa223abb589b1cd3ebd4cd Author: aa Date: Tue Jul 31 03:54:03 2018 +0200 not comparing the addresses of stored objects but their keys --- src/getfem_integration.cc | 3 ++- src/getfem_mesh_im.cc | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/getfem_integration.cc b/src/getfem_integration.cc index 7131cc4..911a2b0 100644 --- a/src/getfem_integration.cc +++ b/src/getfem_integration.cc @@ -322,7 +322,8 @@ namespace getfem { short_type f) { papprox_integration pai = ppi->approx_method(); GMM_ASSERT1(!valid, "Impossible to modify a valid integration method."); -GMM_ASSERT1(pai->structure() == structure()->faces_structure()[f], +GMM_ASSERT1(*key_of_stored_object(pai->structure()) +== *key_of_stored_object(structure()->faces_structure()[f]), "structures missmatch"); GMM_ASSERT1(ppi->type() == IM_APPROX, "Impossible with an exact method."); diff --git a/src/getfem_mesh_im.cc b/src/getfem_mesh_im.cc index 1e4990c..14a3f3b 100644 --- a/src/getfem_mesh_im.cc +++ b/src/getfem_mesh_im.cc @@ -54,9 +54,9 @@ namespace getfem { { im_convexes.sup(cv); touch(); v_num = act_counter(); } } else if (!im_convexes.is_in(cv) || ims[cv] != pim) { GMM_ASSERT1 - (pim->type() == IM_NONE || -basic_structure(linked_mesh_->structure_of_convex(cv)) -== pim->structure(), + (pim->type() == IM_NONE || + *key_of_stored_object(basic_structure(linked_mesh_->structure_of_convex(cv))) +== *key_of_stored_object(pim->structure()), "Incompatibility between integration method " << getfem::name_of_int_method(pim) << " and mesh element " << bgeot::name_of_geometric_trans(linked_mesh_->trans_of_convex(cv)));