Line data Source code
1 : /*
2 : * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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 : // extern headers
34 : #include <iostream>
35 : #include <sstream>
36 : #include <string>
37 :
38 : // include bridge
39 : #include "bridge/bridge.h"
40 : #include "bridge/util.h"
41 : #include "bridge/util_domain_algebra_dependent.h"
42 :
43 : // lib_disc includes
44 : #include "lib_disc/function_spaces/grid_function.h"
45 : #include "lib_disc/function_spaces/grid_function_util.h"
46 : #include "lib_disc/function_spaces/approximation_space.h"
47 :
48 : #include "lib_disc/io/vtkoutput.h"
49 : #include "lib_disc/io/vtk_export_ho.h"
50 : #include "common/profiler/profiler.h"
51 :
52 : #include "../util_overloaded.h"
53 :
54 : using namespace std;
55 :
56 : namespace ug{
57 : namespace bridge{
58 : namespace Output{
59 :
60 : /**
61 : * \defgroup output_bridge Output Bridge
62 : * \ingroup disc_bridge
63 : * \{
64 : */
65 :
66 : /// small wrapper to write a grid function to vtk
67 : template <typename TGridFunction>
68 0 : void WriteGridFunctionToVTK(TGridFunction& u, const char* filename)
69 : {
70 : PROFILE_FUNC();
71 0 : VTKOutput<TGridFunction::dim> out;
72 : out.print(filename, u, true); // TODO: setting of last argument (intended to skip "make consistent", for writing of "raw" data; see (grid_function_util.h')
73 0 : }
74 :
75 : template <int dim>
76 0 : void SaveDomainToVTK(const char* filename, Domain<dim>& domain)
77 : {
78 0 : VTKOutput<dim> out;
79 0 : out.print(filename, domain);
80 0 : }
81 :
82 : /**
83 : * Class exporting the functionality. All functionality that is to
84 : * be used in scripts or visualization must be registered here.
85 : */
86 : struct Functionality
87 : {
88 :
89 : /**
90 : * Function called for the registration of Domain and Algebra dependent parts.
91 : * All Functions and Classes depending on both Domain and Algebra
92 : * are to be placed here when registering. The method is called for all
93 : * available Domain and Algebra types, based on the current build options.
94 : *
95 : * @param reg registry
96 : * @param parentGroup group for sorting of functionality
97 : */
98 : template <typename TDomain, typename TAlgebra>
99 9 : static void DomainAlgebra(Registry& reg, string grp)
100 : {
101 : string suffix = GetDomainAlgebraSuffix<TDomain,TAlgebra>();
102 : string tag = GetDomainAlgebraTag<TDomain,TAlgebra>();
103 :
104 : // typedef
105 : static const int dim = TDomain::dim;
106 : typedef typename TAlgebra::vector_type vector_type;
107 : typedef typename TAlgebra::matrix_type matrix_type;
108 : typedef GridFunction<TDomain, TAlgebra> function_type;
109 :
110 : // VTK Output
111 : {
112 : typedef VTKOutput<dim> T;
113 9 : reg.get_class_<T>()
114 18 : .add_method("write_time_pvd", static_cast<void (T::*)(const char*, function_type&)>(&T::write_time_pvd))
115 18 : .add_method("write_time_processwise_pvd", static_cast<void (T::*)(const char*, function_type&)>(&T::write_time_processwise_pvd))
116 18 : .add_method("write_time_pvd_subset", static_cast<void (T::*)(const char*, function_type&, int)>(&T::write_time_pvd_subset), "", "name # printed grid function # subset index", "", "")
117 18 : .add_method("print", static_cast<void (T::*)(const char*, function_type&, int, number, bool)>(&T::print))
118 18 : .add_method("print", static_cast<void (T::*)(const char*, function_type&, int, number)>(&T::print))
119 18 : .add_method("print", static_cast<void (T::*)(const char*, function_type&, bool)>(&T::print))
120 18 : .add_method("print", static_cast<void (T::*)(const char*, function_type&)>(&T::print))
121 18 : .add_method("print_subset", static_cast<void (T::*)(const char*, function_type&, int, int, number, bool)>(&T::print_subset))
122 18 : .add_method("print_subset", static_cast<void (T::*)(const char*, function_type&, int, int, number)>(&T::print_subset))
123 18 : .add_method("print_subsets", static_cast<void (T::*)(const char*, function_type&, const char*, int, number, bool)>(&T::print_subsets))
124 18 : .add_method("print_subsets", static_cast<void (T::*)(const char*, function_type&, const char*, int, number)>(&T::print_subsets))
125 18 : .add_method("print_subsets", static_cast<void (T::*)(const char*, function_type&, const char*, bool)>(&T::print_subsets))
126 18 : .add_method("print_subsets", static_cast<void (T::*)(const char*, function_type&, const char*)>(&T::print_subsets))
127 : ;
128 : }
129 :
130 : // VTK Output for higher-order functions
131 : {
132 18 : reg.add_function("vtk_export_ho",
133 : static_cast<void (*) (SmartPtr<function_type>, const std::vector<std::string>&, size_t,
134 : SmartPtr<VTKOutput<dim> >, const char*)>
135 : (&vtk_export_ho<function_type>),
136 : grp.c_str(), "new grid function", "input grid function#functions to be exported#order",
137 : "creates a grid function of order 1 containing interpolated values from high-order input grid function on a refined grid");
138 18 : reg.add_function("vtk_export_ho",
139 : static_cast<void (*) (SmartPtr<function_type>, const std::vector<std::string>&, size_t,
140 : SmartPtr<VTKOutput<dim> >, const char*, size_t, number)>
141 : (&vtk_export_ho<function_type>),
142 : grp.c_str(), "new grid function", "input grid function#functions to be exported#order",
143 : "Creates a grid function of order 1 containing interpolated values from high-order input grid function on a refined grid");
144 : }
145 :
146 :
147 : // GridFunctionDebugWriter
148 : {
149 : typedef GridFunctionDebugWriter<TDomain, TAlgebra> T;
150 : typedef IDebugWriter<TAlgebra> TBase;
151 9 : string name = string("GridFunctionDebugWriter").append(suffix);
152 27 : reg.add_class_<T, TBase>(name, grp)
153 18 : .template add_constructor<void (*)(SmartPtr<ApproximationSpace<TDomain> >)>("")
154 27 : .add_method("reset", &T::reset, "", "")
155 36 : .add_method("set_vtk_output", &T::set_vtk_output, "", "bVtkOutput")
156 36 : .add_method("set_conn_viewer_output", &T::set_conn_viewer_output, "", "bCVOutput")
157 36 : .add_method("set_conn_viewer_indices", &T::set_conn_viewer_indices, "", "bIndicesOutput")
158 36 : .add_method("set_print_consistent", &T::set_print_consistent, "", "printConsistent")
159 27 : .add_method("set_grid_level", &T::set_grid_level, "Sets the grid level", "GridLevel")
160 9 : .set_construct_as_smart_pointer(true);
161 27 : reg.add_class_to_group(name, "GridFunctionDebugWriter", tag);
162 : }
163 :
164 : // GridFunctionPositionProvider
165 : {
166 : typedef GridFunctionPositionProvider<function_type> T;
167 : typedef IPositionProvider<dim> TBase;
168 9 : string name = string("GridFunctionPositionProvider").append(suffix);
169 27 : reg.add_class_<T, TBase>(name, grp)
170 9 : .add_constructor()
171 18 : . ADD_CONSTRUCTOR( (const function_type&) )("gridFunction")
172 18 : .add_method("set_reference_grid_function", &T::set_reference_grid_function, "", "gridFunction")
173 9 : .set_construct_as_smart_pointer(true);
174 27 : reg.add_class_to_group(name, "GridFunctionPositionProvider", tag);
175 : }
176 :
177 :
178 : // GridFunctionVectorWriter
179 : {
180 : typedef GridFunctionVectorWriter<function_type, vector_type> T;
181 : typedef IVectorWriter<vector_type> TBase;
182 9 : string name = string("GridFunctionVectorWriter").append(suffix);
183 27 : reg.add_class_<T, TBase>(name, grp)
184 9 : .add_constructor()
185 27 : .add_method("set_reference_grid_function", &T::set_reference_grid_function, "", "gridFunction")
186 27 : .add_method("set_user_data", &T::set_user_data, "", "userData")
187 9 : .set_construct_as_smart_pointer(true);
188 27 : reg.add_class_to_group(name, "GridFunctionVectorWriter", tag);
189 : }
190 :
191 : // GridFunctionVectorWriterDirichlet0
192 : {
193 : typedef GridFunctionVectorWriterDirichlet0<function_type> T;
194 : typedef IVectorWriter<vector_type> TBase;
195 9 : string name = string("GridFunctionVectorWriterDirichlet0").append(suffix);
196 27 : reg.add_class_<T, TBase>(name, grp)
197 9 : .add_constructor()
198 27 : .add_method("init", &T::init, "", "postProcess#approxSpace#level")
199 27 : .add_method("set_level", &T::set_level, "", "level")
200 9 : .set_construct_as_smart_pointer(true);
201 27 : reg.add_class_to_group(name, "GridFunctionVectorWriterDirichlet0", tag);
202 : }
203 :
204 : // WriteGridToVTK
205 : {
206 27 : reg.add_function("WriteGridFunctionToVTK",
207 : &WriteGridFunctionToVTK<function_type>, grp,
208 : "", "GridFunction#Filename|save-dialog|endings=[\"vtk\"];description=\"VTK-Files\"",
209 : "Saves GridFunction to *.vtk file", "No help");
210 : }
211 :
212 : // SaveMatrixForConnectionViewer
213 : {
214 27 : reg.add_function("SaveMatrixForConnectionViewer",
215 : &SaveMatrixForConnectionViewer<function_type>, grp, "", "u#A#Filename|save-dialog|endings=[\"mat\"]");
216 : }
217 :
218 : // SaveVectorForConnectionViewer
219 : {
220 : typedef MatrixOperator<matrix_type, vector_type> matOp;
221 :
222 27 : reg.add_function("SaveVectorForConnectionViewer",OVERLOADED_FUNCTION_PTR
223 : (void, SaveVectorForConnectionViewer<function_type>, (function_type& ,const char*) ) ,
224 : grp, "", "vec#Filename|save-dialog|endings=[\"vec\"]", "save vector as .vec for ConnectionViewer");
225 27 : reg.add_function("SaveVectorDiffForConnectionViewer", OVERLOADED_FUNCTION_PTR
226 : (void, SaveVectorDiffForConnectionViewer<function_type>, (function_type& ,function_type&, const char*) ),
227 : grp, "", "vecA#vecB#Filename|save-dialog|endings=[\"vec\"]", "compare two vectors a and b and save difference in .vec for ConnectionViewer");
228 27 : reg.add_function("SaveVectorForConnectionViewer", OVERLOADED_FUNCTION_PTR
229 : (void, SaveVectorForConnectionViewer<function_type>, (function_type& , matOp&, const char*) ),
230 : grp, "", "vec#matrix#Filename|save-dialog|endings=[\"vec\"]", "save vector as .vec for ConnectionViewer, use matrix connections as a \"grid\"");
231 27 : reg.add_function("SaveVectorDiffForConnectionViewer", OVERLOADED_FUNCTION_PTR
232 : (void, SaveVectorDiffForConnectionViewer<function_type>, (function_type& , function_type& , matOp&, const char*) ),
233 : grp, "", "vecA#veccB#matrix#Filename|save-dialog|endings=[\"vec\"]", "compare two vectors a and b and save difference in .vec for ConnectionViewer, use matrix connections as a \"grid\"");
234 27 : reg.add_function("LoadVector", OVERLOADED_FUNCTION_PTR
235 : (void, LoadVector<function_type>, (function_type& ,const char*) ),
236 : grp, "", "vec#Filename|save-dialog|endings=[\"vec\"]", "save vector as .vec for ConnectionViewer");
237 : }
238 :
239 : // SaveVectorCSV
240 : {
241 27 : reg.add_function("SaveVectorCSV",
242 : &SaveVectorCSV<function_type>, grp, "", "b#filename|save-dialog");
243 : }
244 9 : }
245 :
246 : /**
247 : * Function called for the registration of Dimension dependent parts.
248 : * All Functions and Classes depending on the Dimension
249 : * are to be placed here when registering. The method is called for all
250 : * available Dimension types, based on the current build options.
251 : *
252 : * @param reg registry
253 : * @param parentGroup group for sorting of functionality
254 : */
255 : template <int dim>
256 3 : static void Dimension(Registry& reg, string grp)
257 : {
258 3 : string suffix = GetDimensionSuffix<dim>();
259 3 : string tag = GetDimensionTag<dim>();
260 :
261 9 : reg.add_function("SaveDomainToVTK", &SaveDomainToVTK<dim>, grp, "", "filename|save-dialog#Domain");
262 :
263 : // VTK Output
264 : {
265 : typedef VTKOutput<dim> T;
266 3 : string name = string("VTKOutput").append(suffix);
267 9 : reg.add_class_<T>(name, grp)
268 3 : .add_constructor()
269 9 : .add_method("clear_selection", &T::clear_selection, "", "", "clears the selected output")
270 12 : .add_method("clear_data_selection", &T::clear_data_selection, "", "", "clears the selected UserData output")
271 12 : .add_method("select_all", &T::select_all, "", "", "schedules that all components of the passed discrete functions will be written to file")
272 9 : .add_method("select", static_cast<void (T::*)(const char*, const char*)>(&T::select), "", "fctName#name",
273 : "selects a value of a grid function value to be written. example:\nfctName = \"p\"; name = \"pressure\"\nfctNames = \"u,v,w\"; name = \"velocity\"")
274 6 : .add_method("select", static_cast<void (T::*)(const vector<string>&, const char*)>(&T::select), "", "fctName#name")
275 6 : .add_method("select", static_cast<void (T::*)(SmartPtr<UserData<number, dim> >, const char*)>(&T::select))
276 6 : .add_method("select", static_cast<void (T::*)(SmartPtr<UserData<MathVector<dim>, dim> >, const char*)>(&T::select))
277 6 : .add_method("select", static_cast<void (T::*)(SmartPtr<UserData<MathMatrix<dim,dim>, dim> >, const char*)>(&T::select))
278 6 : .add_method("select_nodal", static_cast<void (T::*)(const char*, const char*)>(&T::select_nodal), "", "", "selects a nodal value of a grid function value to be written")
279 6 : .add_method("select_nodal", static_cast<void (T::*)(const vector<string>&, const char*)>(&T::select_nodal))
280 6 : .add_method("select_nodal", static_cast<void (T::*)(SmartPtr<UserData<number, dim> >, const char*)>(&T::select_nodal))
281 6 : .add_method("select_nodal", static_cast<void (T::*)(SmartPtr<UserData<MathVector<dim>, dim> >, const char*)>(&T::select_nodal))
282 6 : .add_method("select_nodal", static_cast<void (T::*)(SmartPtr<UserData<MathMatrix<dim,dim>, dim> >, const char*)>(&T::select_nodal))
283 6 : .add_method("select_element", static_cast<void (T::*)(const char*, const char*)>(&T::select_element))
284 6 : .add_method("select_element", static_cast<void (T::*)(const vector<string>&, const char*)>(&T::select_element), "", "", "selects a element value of a grid function value to be written")
285 6 : .add_method("select_element", static_cast<void (T::*)(SmartPtr<UserData<number, dim> >, const char*)>(&T::select_element))
286 6 : .add_method("select_element", static_cast<void (T::*)(SmartPtr<UserData<MathVector<dim>, dim> >, const char*)>(&T::select_element))
287 6 : .add_method("select_element", static_cast<void (T::*)(SmartPtr<UserData<MathMatrix<dim,dim>, dim> >, const char*)>(&T::select_element))
288 9 : .add_method("set_binary", &T::set_binary, "", "bBinary", "should values be printed in binary (base64 encoded way ) or plain ascii")
289 9 : .add_method("set_user_defined_comment", static_cast<void (T::*)(const char*)>(&T::set_user_defined_comment))
290 6 : .add_method("set_write_grid", static_cast<void (T::*)(bool)>(&T::set_write_grid))
291 6 : .add_method("set_write_subset_indices", static_cast<void (T::*)(bool)>(&T::set_write_subset_indices))
292 6 : .add_method("set_write_proc_ranks", static_cast<void (T::*)(bool)>(&T::set_write_proc_ranks))
293 3 : .set_construct_as_smart_pointer(true);
294 9 : reg.add_class_to_group(name, "VTKOutput", tag);
295 : }
296 3 : }
297 :
298 : /**
299 : * Function called for the registration of Domain and Algebra independent parts.
300 : * All Functions and Classes not depending on Domain and Algebra
301 : * are to be placed here when registering.
302 : *
303 : * @param reg registry
304 : * @param parentGroup group for sorting of functionality
305 : */
306 1 : static void Common(Registry& reg, string grp)
307 : {
308 : #ifdef UG_CPU_1
309 : // SaveMatrixToMTX
310 : {
311 : typedef MatrixOperator<CPUAlgebra::matrix_type, CPUAlgebra::vector_type> matOp;
312 : // reg.add_function( "SaveMatrixToMTX", static_cast<void (*)(const char*, matOp&)>(&SaveMatrixToMTX), grp );
313 3 : reg.add_function( "SaveMatrixToMTX", static_cast<void (*)(const char*, matOp&, std::string)>(&SaveMatrixToMTX), grp,
314 : "", "filename.mtx|save-dialog|endings=[\"mtx\"];description=\"MatrixMarket Files\"#mat#comment", "Save the assembled matrix of a matrix operator to MatrixMarket format");
315 : }
316 : #endif
317 1 : }
318 :
319 : }; // end Functionality
320 :
321 : // end group output_bridge
322 : /// \}
323 :
324 : }// end Output
325 :
326 : /// \addtogroup output_bridge
327 1 : void RegisterBridge_Output(Registry& reg, string grp)
328 : {
329 1 : grp.append("/Discretization/Output");
330 : typedef Output::Functionality Functionality;
331 :
332 : try{
333 2 : RegisterCommon<Functionality>(reg,grp);
334 2 : RegisterDimensionDependent<Functionality>(reg,grp);
335 1 : RegisterDomainAlgebraDependent<Functionality>(reg,grp);
336 : }
337 0 : UG_REGISTRY_CATCH_THROW(grp);
338 1 : }
339 :
340 :
341 : }// end of namespace bridge
342 : }// end of namespace ug
|