Line data Source code
1 : /*
2 : * Copyright (c) 2012-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 : #include "domain_util.h"
34 : #include "domain_traits.h"
35 : #include "common/util/string_util.h"
36 : #include "common/util/file_util.h"
37 : #include "lib_grid/file_io/file_io.h"
38 : #include "lib_grid/file_io/file_io_ugx.h"
39 : #include "lib_grid/algorithms/geom_obj_util/misc_util.h"
40 : #include "lib_grid/refinement/projectors/projection_handler.h"
41 : #include "common/profiler/profiler.h"
42 :
43 : using namespace std;
44 :
45 : namespace ug{
46 :
47 : template <typename TDomain>
48 0 : void LoadDomain(TDomain& domain, const char* filename)
49 : {
50 0 : LoadDomain(domain, filename, 0);
51 0 : }
52 :
53 : // Use procId = -2 (i.e., 4294967294 for 32bit int) to achieve loading on all procs.
54 : template <typename TDomain>
55 0 : void LoadDomain(TDomain& domain, const char* filename, int procId)
56 : {
57 : PROFILE_FUNC_GROUP("grid");
58 0 : size_t num_ph = 0;
59 : //domain.create_additional_subset_handler("markSH");
60 0 : vector<string> additionalSHNames = domain.additional_subset_handler_names();
61 0 : SPProjectionHandler ph = make_sp(new ProjectionHandler(domain.geometry3d(), domain.subset_handler()));
62 0 : vector<SmartPtr<ISubsetHandler> > ash(additionalSHNames.size());
63 :
64 0 : for(size_t i_name = 0; i_name < additionalSHNames.size(); ++i_name)
65 0 : ash[i_name] = domain.additional_subset_handler(additionalSHNames[i_name]);
66 :
67 0 : domain.set_refinement_projector(ph); // this is required for broadcasting projections in the parallel case
68 :
69 0 : if(!LoadGridFromFile(*domain.grid(), ph, num_ph, *domain.subset_handler(), additionalSHNames, ash,
70 : filename, domain.position_attachment(), procId))
71 : {
72 0 : UG_THROW("LoadDomain: Could not load file: "<<filename);
73 : }
74 :
75 0 : if(num_ph == 0)
76 0 : domain.set_refinement_projector(SPNULL);
77 0 : }
78 :
79 :
80 : template <typename TDomain>
81 0 : void SaveDomain(TDomain& domain, const char* filename)
82 : {
83 : PROFILE_FUNC_GROUP("grid");
84 0 : if(GetFilenameExtension(string(filename)) == string("ugx")){
85 0 : GridWriterUGX ugxWriter;
86 0 : ugxWriter.add_grid(*domain.grid(), "defGrid", domain.position_attachment());
87 0 : ugxWriter.add_subset_handler(*domain.subset_handler(), "defSH", 0);
88 :
89 0 : vector<string> additionalSHNames = domain.additional_subset_handler_names();
90 0 : for(size_t i_name = 0; i_name < additionalSHNames.size(); ++i_name){
91 : const char* shName = additionalSHNames[i_name].c_str();
92 0 : ugxWriter.add_subset_handler(*domain.additional_subset_handler(shName), shName, 0);
93 : }
94 :
95 0 : if(!ugxWriter.write_to_file(filename)){
96 0 : UG_THROW("Couldn't save domain to the specified file: " << filename);
97 : }
98 0 : }
99 0 : else if(!SaveGridToFile(*domain.grid(), *domain.subset_handler(),
100 : filename, domain.position_attachment()))
101 0 : UG_THROW("SaveDomain: Could not save to file: "<<filename);
102 0 : }
103 :
104 :
105 : template <typename TDomain>
106 0 : number MaxElementDiameter(TDomain& domain, int level)
107 : {
108 : typedef typename domain_traits<TDomain::dim>::grid_base_object TElem;
109 0 : return MaxElementDiameter(*domain.grid(), domain.position_accessor(),
110 : domain.grid()->template begin<TElem>(level),
111 0 : domain.grid()->template end<TElem>(level));
112 : }
113 :
114 : template <typename TDomain>
115 0 : number MinElementDiameter(TDomain& domain, int level)
116 : {
117 : typedef typename domain_traits<TDomain::dim>::grid_base_object TElem;
118 0 : return MinElementDiameter(*domain.grid(), domain.position_accessor(),
119 : domain.grid()->template begin<TElem>(level),
120 0 : domain.grid()->template end<TElem>(level));
121 : }
122 :
123 : template void LoadDomain<Domain1d>(Domain1d& domain, const char* filename);
124 : template void LoadDomain<Domain2d>(Domain2d& domain, const char* filename);
125 : template void LoadDomain<Domain3d>(Domain3d& domain, const char* filename);
126 :
127 : template void LoadDomain<Domain1d>(Domain1d& domain, const char* filename, int procId);
128 : template void LoadDomain<Domain2d>(Domain2d& domain, const char* filename, int procId);
129 : template void LoadDomain<Domain3d>(Domain3d& domain, const char* filename, int procId);
130 :
131 : template void SaveDomain<Domain1d>(Domain1d& domain, const char* filename);
132 : template void SaveDomain<Domain2d>(Domain2d& domain, const char* filename);
133 : template void SaveDomain<Domain3d>(Domain3d& domain, const char* filename);
134 :
135 : template number MaxElementDiameter<Domain1d>(Domain1d& domain, int level);
136 : template number MaxElementDiameter<Domain2d>(Domain2d& domain, int level);
137 : template number MaxElementDiameter<Domain3d>(Domain3d& domain, int level);
138 :
139 : template number MinElementDiameter<Domain1d>(Domain1d& domain, int level);
140 : template number MinElementDiameter<Domain2d>(Domain2d& domain, int level);
141 : template number MinElementDiameter<Domain3d>(Domain3d& domain, int level);
142 :
143 : } // end namespace ug
144 :
|