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/algorithms/deg_layer_mngr.h"
36 : #include "lib_grid/algorithms/extrusion/expand_layers.h"
37 : #include "lib_grid/algorithms/grid_generation/horizontal_layers_mesher.h"
38 :
39 : using namespace std;
40 :
41 : namespace ug{
42 : namespace bridge{
43 :
44 : /**
45 : * A template function for registering a degenerated layer manager for a
46 : * specified dimensionality.
47 : */
48 : template <int dim>
49 2 : static void RegisterDegeneratedLayerManager(Registry& reg, string grp)
50 : {
51 2 : string suffix = GetDimensionSuffix<dim>();
52 2 : string tag = GetDimensionTag<dim>();
53 :
54 : typedef DegeneratedLayerManager<dim> T;
55 2 : string name = string("DegeneratedLayerManager").append(suffix);
56 6 : reg.add_class_<T>(name, grp)
57 4 : .template add_constructor<void (*) (SmartPtr<MultiGridSubsetHandler>)>("MultiGridSubsetHandler")
58 4 : .add_method("add", static_cast<void (T::*) (const char*)>(&T::add), "Adds degenerated subsets to the manager", "subset(s)")
59 4 : .add_method("remove", static_cast<void (T::*) (const char*)>(&T::remove), "Removes subsets from the manager", "subset(s)")
60 4 : .add_method("close", static_cast<void (T::*) ()>(&T::close), "Finalizes the fracture manager", "")
61 4 : .add_method("contains", static_cast<bool (T::*) (int)>(&T::contains), "Is subset registered in the manager", "subset(s)")
62 4 : .add_method("num_subsets", static_cast<size_t (T::*) ()>(&T::num_subsets), "Number of subsets in the manager", "")
63 4 : .add_method("subset", static_cast<int (T::*) (size_t)>(&T::subset), "Subset index for a given index in the manager", "index in the manager")
64 4 : .add_method("assign_middle_subset", static_cast<int (T::*) (int, int)>(&T::assign_middle_subset), "Assigns the subset index to the middle manifold", "subset index of the layer#subset index for the middle manifold")
65 4 : .add_method("assign_middle_subset", static_cast<int (T::*) (int, const char*)>(&T::assign_middle_subset), "Assigns the subset index to the middle manifold", "subset index of the layer#subset name for the middle manifold")
66 4 : .add_method("assign_middle_subset", static_cast<int (T::*) (const char*, const char*)>(&T::assign_middle_subset), "Assigns the subset index to the middle manifold", "subset of the layer#subset name for the middle manifold")
67 4 : .add_method("init_refiner", static_cast<void (T::*) (SmartPtr<GlobalFracturedMediaRefiner>,bool)>(&T::init_refiner), "Init. refiner", "refiner#as low dim")
68 2 : .set_construct_as_smart_pointer(true);
69 6 : reg.add_class_to_group(name, "DegeneratedLayerManager", tag);
70 2 : }
71 :
72 : ////////////////////////////////////////////////////////////////////////
73 : /// A helper class for ExpandLayers.
74 : /** This class should never be publicly available, especially since
75 : * deriving from std::vector is a bad idea (compare 'Effective C++').
76 : * However, it is very useful in this situation.
77 : *
78 : * The class simply extends std::vector<FractureInfo> by an add_layer method.
79 : */
80 0 : class ExpandLayersDesc : public std::vector<FractureInfo>
81 : {
82 : public:
83 : ExpandLayersDesc() {}
84 :
85 0 : void add_layer(int subsetInd, int newSubsetInd, number width)
86 : {
87 0 : push_back(FractureInfo(subsetInd, newSubsetInd, width));
88 0 : }
89 : };
90 :
91 :
92 1 : void RegisterGridBridge_Layers(Registry& reg, string parentGroup)
93 : {
94 : string grp = parentGroup;
95 :
96 : #ifdef UG_DIM_2
97 2 : RegisterDegeneratedLayerManager<2> (reg, grp);
98 : #endif
99 : #ifdef UG_DIM_3
100 1 : RegisterDegeneratedLayerManager<3> (reg, grp);
101 : #endif
102 :
103 : typedef vector<FractureInfo> FracInfoVec;
104 3 : reg.add_class_<FracInfoVec>("FractureInfoVec", grp);
105 :
106 3 : reg.add_class_<ExpandLayersDesc, FracInfoVec>("ExpandLayersDesc", grp)
107 1 : .add_constructor()
108 2 : .add_method("add_layer", &ExpandLayersDesc::add_layer)
109 1 : .set_construct_as_smart_pointer(true);
110 :
111 : // \todo: this is uncommented, since in conflict with new vector
112 : // handling of registry. Should be adapted.
113 : // reg.add_function("ExpandLayers2d", &ExpandFractures2d, grp)
114 : // .add_function("ExpandLayers3d", &ExpandFractures3d, grp);
115 :
116 : // prism-meshing
117 3 : reg.add_class_<RasterLayerDesc>("RasterLayerDesc", grp,
118 : "Layer Desc for RasterLayers class")
119 2 : .add_constructor<void (RasterLayerDesc::*)(const std::string&, number)>(
120 : "filename#minLayerHeight")
121 2 : .add_method("filename", &RasterLayerDesc::filename,
122 : "filename", "", "Returns the filename of the given layer-desc")
123 2 : .add_method("min_height", &RasterLayerDesc::min_height,
124 : "minHeight", "", "Returns the minimal height of the given layer-desc")
125 1 : .set_construct_as_smart_pointer(true);
126 :
127 3 : reg.add_class_<Heightfield>("Heightfield", grp, "2d raster with number values")
128 1 : .add_constructor()
129 3 : .add_method("interpolate",
130 : static_cast<number (Heightfield::*)(number, number) const>(&Heightfield::interpolate),
131 : "height", "x#y", "returns the height at the given coordinate using piecewise constant interpolation")
132 4 : .add_method("interpolate",
133 : static_cast<number (Heightfield::*)(number, number, int) const>(&Heightfield::interpolate),
134 : "height", "x#y#order", "returns the height at the given coordinate using the specified interpolation order")
135 3 : .add_method("no_data_value", &Heightfield::no_data_value,
136 : "noDataValue", "", "returns the value which represents an invalid height")
137 2 : .add_method("blur", &Heightfield::blur, "", "alpha, iterations",
138 : "Smoothens the field by adjusting the value of each pixel "
139 : "towards the average of its neighbours")
140 2 : .add_method("eliminate_invalid_cells", &Heightfield::eliminate_invalid_cells,
141 : "success", "", "eliminates invalid cells by repeatedly filling "
142 : "those cells with averages of neighboring cells");
143 :
144 3 : reg.add_function("LoadHeightfieldFromASC", LoadHeightfieldFromASC, grp,
145 : "", "heightfield # filename", "Loads a heightfield from the specified file");
146 :
147 3 : reg.add_class_<RasterLayers>("RasterLayers", grp, "Stack of 2d raster data.")
148 1 : .add_constructor()
149 3 : .add_method("load_from_files",
150 : static_cast<void (RasterLayers::*)(const std::vector<std::string>&, number)>(
151 : &RasterLayers::load_from_files),
152 : "", "filenames", "Loads raster data from the specified .asc files. "
153 : "Specify the bottom layer first and the surface layer last.")
154 4 : .add_method("load_from_files",
155 : static_cast<void (RasterLayers::*)(
156 : const std::vector<SPRasterLayerDesc>&)>(
157 : &RasterLayers::load_from_files),
158 : "", "filenames", "Loads raster data from the specified .asc files. "
159 : "Specify the bottom layer first and the surface layer last.")
160 3 : .add_method("invalidate_flat_cells", &RasterLayers::invalidate_flat_cells, "",
161 : "min height", "Marks all cells as invalid that belong to a "
162 : "small lense regarding its horizontal area.")
163 2 : .add_method("invalidate_small_lenses", &RasterLayers::invalidate_small_lenses, "",
164 : "min area", "Marks all cells as invalid which are closer to the "
165 : "next higher valid cell than the given min height.")
166 2 : .add_method("remove_small_holes", &RasterLayers::remove_small_holes, "",
167 : "max area, min height", "removes small holes by expanding the layer "
168 : "in those regions to the specified height")
169 2 : .add_method("snap_cells_to_higher_layers", &RasterLayers::snap_cells_to_higher_layers, "",
170 : "min height", "sets invalid or flat cells to the value of the corresponding "
171 : "cell in the level above.")
172 2 : .add_method("eliminate_invalid_cells", &RasterLayers::eliminate_invalid_cells, "success",
173 : "eliminates invalid cells by filling those cells with averages of neighboring valid cells.")
174 2 : .add_method("blur_layers", &RasterLayers::blur_layers, "",
175 : "alpha # num iterations", "Blurs the values in each layer by averaging between "
176 : "neighbored cells on the same layer.")
177 2 : .add_method("construct_relative_to_global_height_table",
178 : &RasterLayers::construct_relative_to_global_height_table,
179 : "", "iterations # alpha",
180 : "Prepares a table for improved height value reconstructions in no-data-regions.")
181 1 : .set_construct_as_smart_pointer(true);
182 :
183 1 : }
184 :
185 : }// end of namespace
186 : }// end of namespace
|