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 : if(!LoadGridFromFile(*domain.grid(), ph, num_ph, *domain.subset_handler(), additionalSHNames, ash,
68 : filename, domain.position_attachment(), procId))
69 : {
70 0 : UG_THROW("LoadDomain: Could not load file: "<<filename);
71 : }
72 :
73 0 : if(num_ph != 0)
74 0 : domain.set_refinement_projector(ph);
75 0 : }
76 :
77 :
78 : template <typename TDomain>
79 0 : void SaveDomain(TDomain& domain, const char* filename)
80 : {
81 : PROFILE_FUNC_GROUP("grid");
82 0 : if(GetFilenameExtension(string(filename)) == string("ugx")){
83 0 : GridWriterUGX ugxWriter;
84 0 : ugxWriter.add_grid(*domain.grid(), "defGrid", domain.position_attachment());
85 0 : ugxWriter.add_subset_handler(*domain.subset_handler(), "defSH", 0);
86 :
87 0 : vector<string> additionalSHNames = domain.additional_subset_handler_names();
88 0 : for(size_t i_name = 0; i_name < additionalSHNames.size(); ++i_name){
89 : const char* shName = additionalSHNames[i_name].c_str();
90 0 : ugxWriter.add_subset_handler(*domain.additional_subset_handler(shName), shName, 0);
91 : }
92 :
93 0 : if(!ugxWriter.write_to_file(filename)){
94 0 : UG_THROW("Couldn't save domain to the specified file: " << filename);
95 : }
96 0 : }
97 0 : else if(!SaveGridToFile(*domain.grid(), *domain.subset_handler(),
98 : filename, domain.position_attachment()))
99 0 : UG_THROW("SaveDomain: Could not save to file: "<<filename);
100 0 : }
101 :
102 :
103 : template <typename TDomain>
104 0 : number MaxElementDiameter(TDomain& domain, int level)
105 : {
106 : typedef typename domain_traits<TDomain::dim>::grid_base_object TElem;
107 0 : return MaxElementDiameter(*domain.grid(), domain.position_accessor(),
108 : domain.grid()->template begin<TElem>(level),
109 0 : domain.grid()->template end<TElem>(level));
110 : }
111 :
112 : template <typename TDomain>
113 0 : number MinElementDiameter(TDomain& domain, int level)
114 : {
115 : typedef typename domain_traits<TDomain::dim>::grid_base_object TElem;
116 0 : return MinElementDiameter(*domain.grid(), domain.position_accessor(),
117 : domain.grid()->template begin<TElem>(level),
118 0 : domain.grid()->template end<TElem>(level));
119 : }
120 :
121 : template void LoadDomain<Domain1d>(Domain1d& domain, const char* filename);
122 : template void LoadDomain<Domain2d>(Domain2d& domain, const char* filename);
123 : template void LoadDomain<Domain3d>(Domain3d& domain, const char* filename);
124 :
125 : template void LoadDomain<Domain1d>(Domain1d& domain, const char* filename, int procId);
126 : template void LoadDomain<Domain2d>(Domain2d& domain, const char* filename, int procId);
127 : template void LoadDomain<Domain3d>(Domain3d& domain, const char* filename, int procId);
128 :
129 : template void SaveDomain<Domain1d>(Domain1d& domain, const char* filename);
130 : template void SaveDomain<Domain2d>(Domain2d& domain, const char* filename);
131 : template void SaveDomain<Domain3d>(Domain3d& domain, const char* filename);
132 :
133 : template number MaxElementDiameter<Domain1d>(Domain1d& domain, int level);
134 : template number MaxElementDiameter<Domain2d>(Domain2d& domain, int level);
135 : template number MaxElementDiameter<Domain3d>(Domain3d& domain, int level);
136 :
137 : template number MinElementDiameter<Domain1d>(Domain1d& domain, int level);
138 : template number MinElementDiameter<Domain2d>(Domain2d& domain, int level);
139 : template number MinElementDiameter<Domain3d>(Domain3d& domain, int level);
140 :
141 : } // end namespace ug
142 :
|