LCOV - code coverage report
Current view: top level - ugbase/bridge/grid_bridges - refinement_bridge.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 84.1 % 151 127
Test Date: 2025-09-21 23:31:46 Functions: 33.3 % 3 1

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #include "grid_bridges.h"
      34              : #include "bridge/suffix_tag.h"
      35              : #include "lib_grid/refinement/adaptive_regular_mg_refiner.h"
      36              : #include "lib_grid/refinement/global_fractured_media_refiner.h"
      37              : #include "lib_grid/refinement/global_multi_grid_refiner.h"
      38              : #include "lib_grid/refinement/global_subdivision_multi_grid_refiner.h"
      39              : #include "lib_grid/refinement/hanging_node_refiner_grid.h"
      40              : #include "lib_grid/refinement/hanging_node_refiner_multi_grid.h"
      41              : #include "lib_grid/refinement/projectors/projectors.h"
      42              : #include "lib_grid/algorithms/subdivision/subdivision_loop.h"
      43              : #include "lib_grid/file_io/file_io.h"
      44              : 
      45              : #ifdef UG_PARALLEL
      46              : #include "lib_grid/parallelization/parallel_refinement/parallel_hanging_node_refiner_multi_grid.h"
      47              : #endif
      48              : 
      49              : using namespace std;
      50              : 
      51              : namespace ug{
      52              : namespace bridge{
      53              : 
      54            0 : bool CreateHierarchy(MultiGrid& mg, size_t numRefs)
      55              : {
      56              :         PROFILE_FUNC_GROUP("grid");
      57              : 
      58            0 :         GlobalMultiGridRefiner ref(mg);
      59              : 
      60            0 :         for(size_t lvl = 0; lvl < numRefs; ++lvl){
      61            0 :                 ref.refine();
      62              :         }
      63            0 :         return true;
      64            0 : }
      65              : 
      66            0 : bool CreateSmoothHierarchy(MultiGrid& mg, size_t numRefs)
      67              : {
      68              :         PROFILE_FUNC_GROUP("grid");
      69              : 
      70              : //      we're only checking for the main attachments here.
      71              : //todo: improve this - add a domain-based hierarchy creator.
      72              :         SPRefinementProjector projector;
      73            0 :         if(mg.has_vertex_attachment(aPosition1))
      74            0 :                 projector = make_sp(new SubdivisionProjector(MakeGeometry3d(mg, aPosition1)));
      75            0 :         else if(mg.has_vertex_attachment(aPosition2))
      76            0 :                 projector = make_sp(new SubdivisionProjector(MakeGeometry3d(mg, aPosition2)));
      77            0 :         else if(mg.has_vertex_attachment(aPosition))
      78            0 :                 projector = make_sp(new SubdivisionProjector(MakeGeometry3d(mg, aPosition)));
      79              :                 
      80            0 :         if(!projector.valid()){
      81              :                 UG_LOG("No standard position attachment found. Aborting.\n");
      82              :                 return false;
      83              :         }
      84              :         
      85            0 :         GlobalMultiGridRefiner ref(mg, projector);
      86              : 
      87            0 :         for(size_t lvl = 0; lvl < numRefs; ++lvl){
      88            0 :                 ref.refine();
      89              :         }
      90              : 
      91            0 :         if(mg.has_vertex_attachment(aPosition1))
      92            0 :                 ProjectToLimitPLoop(mg, aPosition1, aPosition1);
      93            0 :         else if(mg.has_vertex_attachment(aPosition2))
      94            0 :                 ProjectToLimitPLoop(mg, aPosition2, aPosition2);
      95            0 :         else if(mg.has_vertex_attachment(aPosition))
      96            0 :                 ProjectToLimitPLoop(mg, aPosition, aPosition);
      97              : 
      98              :         return true;
      99            0 : }
     100              : 
     101            1 : void RegisterGridBridge_Refinement(Registry& reg, string parentGroup)
     102              : {
     103              :         string grp = parentGroup;
     104              : //      refinement projectors
     105              :         {
     106              :                 typedef RefinementProjector T;
     107            3 :                 reg.add_class_<T>("RefinementProjector", grp)
     108            2 :                         .add_method("set_geometry", &T::set_geometry, "", "geometry")
     109            2 :                         .add_method("geometry", &T::geometry, "geometry", "");
     110              :         }
     111              : 
     112              :         {
     113              :                 typedef CylinderCutProjector T;
     114            3 :                 reg.add_class_<T, RefinementProjector>("CylinderCutProjector", grp)
     115            1 :                         .add_constructor()
     116            2 :                         .add_constructor<void (T::*)(const vector3&, const vector3&, number)>()
     117            2 :                         .add_constructor<void (T::*)(SPIGeometry3d, const vector3&, const vector3&, number)>()
     118            2 :                         .add_method("set_center", &T::set_center, "", "center")
     119            2 :                         .add_method("center", &T::center, "center")
     120            2 :                         .add_method("set_axis", &T::set_axis, "", "axis")
     121            2 :                         .add_method("axis", &T::axis, "axis")
     122            2 :                         .add_method("set_radius", &T::set_radius, "", "radius")
     123            2 :                         .add_method("radius", &T::radius, "radius")
     124            1 :                         .set_construct_as_smart_pointer(true);
     125              :         }
     126              : 
     127              :         {
     128              :                 typedef CylinderProjector T;
     129            3 :                 reg.add_class_<T, RefinementProjector>("CylinderProjector", grp)
     130            1 :                         .add_constructor()
     131            2 :                         .add_constructor<void (T::*)(const vector3&, const vector3&)>()
     132            2 :                         .add_constructor<void (T::*)(const vector3&, const vector3&, number)>()
     133              :                         .add_constructor<void (T::*)(const vector3&, const vector3&, number,
     134            2 :                                                                                  number)>()
     135              :                         .add_constructor<void (T::*)(SPIGeometry3d, const vector3&,
     136            2 :                                                                                  const vector3&, number, number)>()
     137            2 :                         .add_method("set_center", &T::set_center, "", "center")
     138            2 :                         .add_method("center", &T::center, "center")
     139            2 :                         .add_method("set_axis", &T::set_axis, "", "axis")
     140            2 :                         .add_method("axis", &T::axis, "axis")
     141            2 :                         .add_method("set_radius", &T::set_radius, "", "radius")
     142            2 :                         .add_method("radius", &T::radius, "radius")
     143            2 :                         .add_method("set_influence_radius", &T::set_influence_radius, "", "influenceRadius")
     144            2 :                         .add_method("influence_radius", &T::influence_radius, "influenceRadius")
     145            1 :                         .set_construct_as_smart_pointer(true);
     146              :         }
     147              : 
     148              :         {
     149              :                 typedef PlaneCutProjector T;
     150            3 :                 reg.add_class_<T, RefinementProjector>("PlaneCutProjector", grp)
     151            1 :                         .add_constructor()
     152            2 :                         .add_constructor<void (T::*)(const vector3&, const vector3&)>()
     153              :                         .add_constructor<void (T::*)(SPIGeometry3d, const vector3&,
     154            2 :                                                                                  const vector3&)>()
     155            2 :                         .add_method("set_position", &T::set_position, "", "position")
     156            2 :                         .add_method("position", &T::position, "position")
     157            2 :                         .add_method("set_normal", &T::set_normal, "", "normal")
     158            2 :                         .add_method("normal", &T::normal, "normal")
     159            1 :                         .set_construct_as_smart_pointer(true);
     160              :         }
     161              : 
     162              :         {
     163              :                 typedef ProjectionHandler T;
     164            3 :                 reg.add_class_<T, RefinementProjector>("ProjectionHandler", grp)
     165            1 :                         .add_constructor()
     166            2 :                         .add_constructor<void (T::*)(ISubsetHandler*)>()
     167            2 :                         .add_constructor<void (T::*)(SmartPtr<ISubsetHandler>)>()
     168              :                         .add_constructor<void (T::*)(SPIGeometry3d,
     169            2 :                                                                                  ISubsetHandler*)>()
     170              :                         .add_constructor<void (T::*)(SPIGeometry3d,
     171            2 :                                                                                  SmartPtr<ISubsetHandler>)>()
     172            2 :                         .add_method("set_geometry_all", &T::set_geometry_all, "", "geometry")
     173            2 :                         .add_method("set_projector",
     174              :                                                 static_cast<void (T::*)(int, SPRefinementProjector)>(
     175              :                                                                 &T::set_projector),
     176              :                                                 "", "subsetIndex # projector")
     177            2 :                         .add_method("set_projector",
     178              :                                                 static_cast<void (T::*)(const char*, SPRefinementProjector)>(
     179              :                                                                 &T::set_projector),
     180              :                                                 "", "subsetName # projector")
     181            1 :                         .set_construct_as_smart_pointer(true);
     182              :         }
     183              : 
     184              :         {
     185              :                 typedef SmoothProjector T;
     186            3 :                 reg.add_class_<T, RefinementProjector>("SmoothProjector", grp)
     187            1 :                         .add_constructor()
     188            2 :                         .add_constructor<void (T::*)(int, number)>()
     189            2 :                         .add_constructor<void (T::*)(SPIGeometry3d, int, number)>()
     190            2 :                         .add_method("set_iterations", &T::set_iterations, "", "iterations")
     191            2 :                         .add_method("iterations", &T::iterations, "iterations")
     192            2 :                         .add_method("set_change_rate", &T::set_change_rate, "", "changeRate")
     193            2 :                         .add_method("change_rate", &T::change_rate, "changeRate")
     194            1 :                         .set_construct_as_smart_pointer(true);
     195              :         }
     196              : 
     197              :         {
     198              :                 typedef SphereProjector T;
     199            3 :                 reg.add_class_<T, RefinementProjector>("SphereProjector", grp)
     200            1 :                         .add_constructor()
     201            2 :                         .add_constructor<void (T::*)(const vector3&)>()
     202            2 :                         .add_constructor<void (T::*)(const vector3&, number)>()
     203            2 :                         .add_constructor<void (T::*)(const vector3&, number, number)>()
     204              :                         .add_constructor<void (T::*)(SPIGeometry3d, const vector3&,
     205            2 :                                                                                  number, number)>()
     206            2 :                         .add_method("set_center", &T::set_center, "", "center")
     207            2 :                         .add_method("center", &T::center, "center")
     208            2 :                         .add_method("set_radius", &T::set_radius, "", "radius")
     209            2 :                         .add_method("radius", &T::radius, "radius")
     210            2 :                         .add_method("set_influence_radius", &T::set_influence_radius, "", "influenceRadius")
     211            2 :                         .add_method("influence_radius", &T::influence_radius, "influenceRadius")
     212            1 :                         .set_construct_as_smart_pointer(true);
     213              :         }
     214              : 
     215              :         {
     216              :                 typedef SubdivisionProjector T;
     217            3 :                 reg.add_class_<T, RefinementProjector>("SubdivisionProjector", grp)
     218            1 :                         .add_constructor()
     219            2 :                         .add_constructor<void (T::*)(SPIGeometry3d)>()
     220            1 :                         .set_construct_as_smart_pointer(true);
     221              :         }
     222              :         
     223              : //      IRefiner
     224            3 :         reg.add_class_<IRefiner>("IRefiner", grp)
     225            2 :                 .add_method("refine", &IRefiner::refine)
     226            2 :                 .add_method("coarsen", &IRefiner::coarsen)
     227            2 :                 .add_method("save_marks_to_file", &IRefiner::save_marks_to_file, "", "filename")
     228            2 :                 .add_method("set_adjusted_marks_debug_filename", &IRefiner::set_adjusted_marks_debug_filename, "", "filename")
     229            3 :                 .add_method("mark_neighborhood",
     230              :                                         static_cast<void (IRefiner::*)(size_t)>(&IRefiner::mark_neighborhood),
     231              :                                         "", "numIterations")
     232            3 :                 .add_method("clear_marks", &IRefiner::clear_marks)
     233            2 :                 .add_method("set_projector", &IRefiner::set_projector)
     234            2 :                 .add_method("enable_debugging", &IRefiner::enable_debugging)
     235            3 :                 .add_method("num_marked_edges", static_cast<size_t (IRefiner::*)()>(&IRefiner::num_marked_edges))
     236            4 :                 .add_method("num_marked_faces", static_cast<size_t (IRefiner::*)()>(&IRefiner::num_marked_faces))
     237            4 :                 .add_method("num_marked_volumes", static_cast<size_t (IRefiner::*)()>(&IRefiner::num_marked_volumes))
     238            3 :                 .add_method("num_marked_elements", static_cast<size_t (IRefiner::*)()>(&IRefiner::num_marked_elements));
     239              : 
     240              : //      RefMarkAdjusters
     241            3 :         reg.add_class_<IRefMarkAdjuster>("IRefMarkAdjuster", grp)
     242            2 :                 .add_method("enable", &IRefMarkAdjuster::enable, "", "enable")
     243            2 :                 .add_method("enabled", &IRefMarkAdjuster::enabled, "enabled", "");
     244              : 
     245              : //      HangingNodeRefiner
     246            3 :         reg.add_class_<HangingNodeRefiner_Grid, IRefiner>("HangingNodeRefiner_Grid", grp)
     247            1 :                 .add_constructor()
     248            2 :                 .add_method("assign_grid", &HangingNodeRefiner_Grid::assign_grid, "", "g")
     249            1 :                 .set_construct_as_smart_pointer(true);
     250              : 
     251            3 :         reg.add_class_<HangingNodeRefiner_MultiGrid, IRefiner>("HangingNodeRefiner_MultiGrid", grp)
     252            1 :                 .add_constructor()
     253            2 :                 .add_method("assign_grid", &HangingNodeRefiner_MultiGrid::assign_grid, "", "mg")
     254            1 :                 .set_construct_as_smart_pointer(true);
     255              : 
     256              : //      AdaptiveRegularMGRefiner
     257            3 :         reg.add_class_<AdaptiveRegularRefiner_MultiGrid, HangingNodeRefiner_MultiGrid>("AdaptiveRegularRefiner_MultiGrid", grp)
     258            1 :                 .add_constructor()
     259            2 :                 .add_method("assign_grid", &AdaptiveRegularRefiner_MultiGrid::assign_grid, "", "mg")
     260            1 :                 .set_construct_as_smart_pointer(true);
     261              : 
     262              : //      GlobalMultiGridRefiner
     263            3 :         reg.add_class_<GlobalMultiGridRefiner, IRefiner>("GlobalMultiGridRefiner", grp)
     264            1 :                 .add_constructor()
     265            2 :                 .add_method("assign_grid", static_cast<void (GlobalMultiGridRefiner::*)(MultiGrid&)>(&GlobalMultiGridRefiner::assign_grid),
     266              :                                 "", "mg")
     267            1 :                 .set_construct_as_smart_pointer(true);
     268              : 
     269              :         {
     270              :                 typedef GlobalSubdivisionMultiGridRefiner<APosition1> T1D;
     271              :                 typedef GlobalSubdivisionMultiGridRefiner<APosition2> T2D;
     272              :                 typedef GlobalSubdivisionMultiGridRefiner<APosition> T3D;
     273            1 :                 std::string name = "GlobalSubdivisionMultiGridRefiner";
     274            3 :                 reg.add_class_<T3D, GlobalMultiGridRefiner>(name + GetDimensionSuffix<3>(), grp)
     275              : //                      .template add_constructor<void (*)(MultiGrid&, APosition&, MGSubsetHandler&, MGSubsetHandler&, SmartPtr<RefinementProjector>)>()
     276              : #ifdef UG_FOR_VRL
     277              :                         .template add_constructor<void (*)(SmartPtr<RefinementProjector>)>()
     278              : #endif
     279            2 :                         .add_method("nest_hierarchy", static_cast<void (T3D::*)()>(&GlobalSubdivisionMultiGridRefiner<APosition>::nest_hierarchy), "", "", "");
     280              : //                      .set_construct_as_smart_pointer(true);
     281            3 :                 reg.add_class_to_group(name + GetDimensionSuffix<3>(), name, GetDimensionTag<3>());
     282              : 
     283            3 :                 reg.add_class_<T2D, GlobalMultiGridRefiner>(name + GetDimensionSuffix<2>(), grp)
     284              : //                      .template add_constructor<void (*)(MultiGrid&, APosition2&, MGSubsetHandler&, MGSubsetHandler&, SmartPtr<RefinementProjector>)>()
     285              : #ifdef UG_FOR_VRL
     286              :                         .template add_constructor<void (*)(SmartPtr<RefinementProjector>)>()
     287              : #endif
     288            2 :                         .add_method("nest_hierarchy", static_cast<void (T2D::*)()>(&GlobalSubdivisionMultiGridRefiner<APosition2>::nest_hierarchy), "", "", "");
     289              : //                      .set_construct_as_smart_pointer(true);
     290            3 :                 reg.add_class_to_group(name + GetDimensionSuffix<2>(), name, GetDimensionTag<2>());
     291              : 
     292            3 :                 reg.add_class_<T1D, GlobalMultiGridRefiner>(name + GetDimensionSuffix<1>(), grp)
     293              : //                      .template add_constructor<void (*)(MultiGrid&, APosition1&, MGSubsetHandler&, MGSubsetHandler&, SmartPtr<RefinementProjector>)>()
     294              : #ifdef UG_FOR_VRL
     295              :                         .template add_constructor<void (*)(SmartPtr<RefinementProjector>)>()
     296              : #endif
     297            2 :                         .add_method("nest_hierarchy", static_cast<void (T1D::*)()>(&GlobalSubdivisionMultiGridRefiner<APosition1>::nest_hierarchy), "", "", "");
     298              : //                      .set_construct_as_smart_pointer(true);
     299            3 :                 reg.add_class_to_group(name + GetDimensionSuffix<1>(), name, GetDimensionTag<1>());
     300              :         }
     301              : 
     302              : //      FracturedMediaRefiner
     303              :         /*typedef FracturedMediaRefiner<typename TDomain::grid_type,
     304              :                                                                   typename TDomain::position_attachment_type>        FracDomRef;
     305              :         reg.add_class_<FracDomRef, IRefiner>("FracturedMediumRefiner", grp)
     306              :                 .add_constructor()
     307              :                 .add_method("set_aspect_ratio_threshold", &FracDomRef::set_aspect_ratio_threshold);*/
     308              : 
     309              : //      GlobalFracturedDomainRefiner
     310              :         {
     311              :                 typedef GlobalFracturedMediaRefiner cls;
     312            3 :                 reg.add_class_<cls, IRefiner>("GlobalFracturedMediumRefiner", grp)
     313            1 :                         .add_constructor()
     314            2 :                         .add_method("assign_grid", static_cast<void (cls::*)(MultiGrid*)>(&cls::assign_grid), "", "g")
     315            2 :                         .add_method("set_subset_handler", static_cast<void (cls::*)(ISubsetHandler*)>(&cls::set_subset_handler),
     316              :                                         "", "sh")
     317            2 :                         .add_method("mark_as_fracture", &cls::mark_as_fracture, "", "subInd#bIsFracture")
     318            2 :                         .add_method("is_fracture", &cls::is_fracture, "", "subInd")
     319            1 :                         .set_construct_as_smart_pointer(true);
     320              :         }
     321              : 
     322              : //      parallel refinement
     323              : #ifdef UG_PARALLEL
     324              :         reg.add_class_<ParallelHangingNodeRefiner_MultiGrid, HangingNodeRefiner_MultiGrid>
     325              :                 ("ParallelHangingNodeRefiner_MultiGrid", grp)
     326              :                 .add_constructor()
     327              :                 .set_construct_as_smart_pointer(true);
     328              : /*Currently not directly usable. For domains, you may use the factory method
     329              : * GlobalFracturedDomainRefiner, which automatically creates a
     330              : * ParallelGlobalFracturedMediaRefiner, if required.
     331              :         reg.add_class_<ParallelGlobalFracturedMediaRefiner, GlobalFracturedMediaRefiner>
     332              :                 ("ParallelGlobalFracturedMediaRefiner", grp)
     333              :                 .add_constructor()
     334              :                 .set_construct_as_smart_pointer(true);
     335              : */
     336              : #endif
     337              : 
     338              : //      refinement
     339            3 :         reg.add_function("CreateHierarchy", &CreateHierarchy, grp)
     340            3 :                 .add_function("CreateSmoothHierarchy", &CreateSmoothHierarchy, grp);
     341            1 : }
     342              : 
     343              : }//     end of namespace
     344              : }//     end of namespace
        

Generated by: LCOV version 2.0-1