Loading [MathJax]/extensions/tex2jax.js
Plugins
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
em_material_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2014: G-CSC, Goethe University Frankfurt
3 * Author: Dmitry Logashenko
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
37
38namespace ug{
39namespace Electromagnetism{
40
44template <typename TDomain>
46(
48)
49: m_spDomain (domain),
50 m_bClosed (false)
51{
52 if (domain.invalid () || subset_handler().invalid ())
53 UG_THROW ("EMaterial: Invalid domain or subset handler.");
54}
55
63template <typename TDomain>
65(
66 int si,
67 number& mu,
68 number& sigma
69) const
70{
71 TSubdomData * pSdD;
72
73 if (! m_bClosed)
74 UG_THROW ("EMaterial: Attempt to get data from a unfinalized object.")
75
76 typename t_data_map::const_iterator iter = m_mUserDataBC.find (si);
77 if (iter == m_mUserDataBC.end () || (pSdD = iter->second) == NULL)
78 return true;
79
80 mu = pSdD->mu;
81 sigma = pSdD->sigma;
82 return false;
83}
84
88template <typename TDomain>
90(
91 const char * subsets,
92 number mu,
93 number sigma
94)
95{
96// Check if already finalized
97 if (m_bClosed)
98 UG_THROW ("EMaterial::add:"
99 " Attempt to add a subset data item to a finalized domain description.");
100
101// Add a new element
102 m_vSdD.push_back (TSubdomData (subset_handler (), subsets, mu, sigma));
103}
104
108template <typename TDomain>
110{
111 std::vector<std::string> vssNames;
112
113// Clear the map and remove all the subset indices:
114 m_bClosed = false;
115 m_mUserDataBC.clear ();
116 m_sSsNames = "";
117
118 if (m_vSdD.size () == 0)
119 UG_THROW ("No data items specified.");
120
121// Parse the subset names:
122 try
123 {
124 for (size_t i = 0; i < m_vSdD.size (); i++)
125 {
126 TSubdomData & sdD = m_vSdD [i];
127 TokenizeString (sdD.ssNames, vssNames);
128 for (size_t k = 0; k < vssNames.size (); k++)
129 RemoveWhitespaceFromString (vssNames [k]);
130 sdD.ssGrp.clear ();
131 sdD.ssGrp.add (vssNames);
132 }
133 } UG_CATCH_THROW ("EMaterial::close: Failed to parse subset names.");
134
135// Get the subset handler:
136 const subset_handler_type * ss_handler = subset_handler().get ();
137
138// Fill the map with the appropriate subsets:
139 for (int si = 0; si < ss_handler->num_subsets (); si++)
140 if (DimensionOfSubset (*ss_handler, si) == dim) // do not consider low-dimensional subsets
141 m_mUserDataBC [si] = 0;
142
143// Fill the map with the data items:
144 for (size_t i = 0; i < m_vSdD.size (); i++)
145 {
146 TSubdomData * psdD = & (m_vSdD [i]);
147 const SubsetGroup & ssg = psdD->ssGrp;
148 for (size_t k = 0; k < ssg.size (); k++)
149 {
150 typename t_data_map::iterator iter = m_mUserDataBC.find (ssg [k]);
151 if (iter == m_mUserDataBC.end ())
152 UG_THROW ("EMaterial::close: Refered subset " << ssg.name (k) << "has an illegal dimension.");
153 if (iter->second != NULL)
154 UG_THROW ("EMaterial::close: Two data items refer to subset " << ssg.name (k) << ".");
155 iter->second = psdD;
156 }
157 }
158
159// Check if there are full-dim. subsets that have not been mentioned:
160 for (typename t_data_map::iterator iter = m_mUserDataBC.begin ();
161 iter != m_mUserDataBC.end (); ++iter)
162 if (iter->second == NULL)
163 UG_THROW ("EMaterial::close: Subset "
164 << ss_handler->get_subset_name (iter->first)
165 << " not mentioned in the description.");
166
167// Analyze the topology
168 analyze_topology ();
169
170// Compose the string of all the names
171 m_sSsNames = m_vSdD[0].ssNames;
172 for (size_t i = 1; i < m_vSdD.size (); i++)
173 {
174 m_sSsNames += ',';
175 m_sSsNames += m_vSdD[i].ssNames;
176 }
177
178// Mark the object as finalized:
179 m_bClosed = true;
180
181// Print the 'greeting':
182 UG_LOG ("Materials specified. " << m_baseConductors.size () << " conductive parts found.\n");
183}
184
194template <typename TDomain>
196(
197 std::vector<int> & minCondInd
198)
199{
200// The full-dim. grid element types for this dimension:
201 typedef typename domain_traits<dim>::grid_base_object t_base_object;
202
203// Initialize the marks of the conductor subsets:
204 std::vector<bool> isConductor (subset_handler()->num_subsets ());
205
206 for (size_t si = 0; si < isConductor.size (); si++)
207 {
208 typename t_data_map::iterator iter = m_mUserDataBC.find (si);
209 if (iter == m_mUserDataBC.end () || iter->second == NULL) // if no data
210 isConductor [si] = false; // skip it
211 else if (iter->second->sigma == (number) 0) // if insulator
212 isConductor [si] = false; // skip it, too
213 else
214 isConductor [si] = true; // this one should be considered
215 }
216
217// Find out the subset connectivity:
218 FindSubsetGroups<t_base_object> (minCondInd, isConductor, * subset_handler().get(),
220
221// Note that the low-dimensional subsets have been "not-marked" and got '-1'
222// in minCondInd. As '-1' should denote the insulators only, we revise the
223// array. Furthermore, there should be no marks '-2' at all because none of
224// the low-dimensional subsets have been marked. We check it to be on the
225// safe side:
226 for (size_t si = 0; si < minCondInd.size (); si++)
227 if (minCondInd [si] == -1) // check whether this is an insulator
228 {
229 if (m_mUserDataBC.find (si) == m_mUserDataBC.end ())
230 minCondInd [si] = -2; // this is no insulator; otherwise, there would be data for it
231 }
232 else if (minCondInd [si] < -1) // check for marked low-dimensional subdomains
233 UG_THROW ("EMaterial::connectivity: Low-dimensional conductor found (subset index " << si << ").");
234};
235
239template <typename TDomain>
241{
242// Get the connectivity:
243 connectivity (m_minCondSsI);
244
245// Compose the list of the minimum conductor subset indices:
246 std::vector<bool> is_min_index (m_minCondSsI.size ());
247 for (size_t i = 0; i < m_minCondSsI.size (); i++)
248 {
249 is_min_index [i] = false; // note that (m_minCondSsI[i] <= i)
250 if (m_minCondSsI[i] >= 0)
251 is_min_index [m_minCondSsI[i]] = true;
252 }
253 m_baseConductors.clear ();
254 for (size_t i = 0; i < is_min_index.size (); i++)
255 if (is_min_index [i])
256 m_baseConductors.push_back (i);
257
258// Compose the references to the base conductors
259 m_baseCondInd.resize (m_minCondSsI.size ());
260 for (size_t i = 0; i < m_minCondSsI.size (); i++)
261 {
262 int min_cond_ssi = m_minCondSsI [i];
263 if (min_cond_ssi <= -2)
264 m_baseCondInd [i] = min_cond_ssi;
265 else
266 m_baseCondInd [i] = -1; // to be on the safe side
267 }
268 for (size_t base_cond = 0; base_cond < m_baseConductors.size (); base_cond++)
269 {
270 int base_cond_si = m_baseConductors [base_cond];
271 for (size_t i = 0; i < m_minCondSsI.size (); i++)
272 if (m_minCondSsI [i] == base_cond_si)
273 m_baseCondInd [i] = base_cond;
274 }
275}
276
277} // end namespace Electromagnetism
278} // end namespace ug
279
280/* End of File */
bool invalid() const
T * get()
void add(const char *subsets, number mu, number sigma)
adds a generic subset data item
Definition em_material_impl.h:90
void connectivity(std::vector< int > &minCondInd)
computes the connectivity of the conductions
Definition em_material_impl.h:196
bool get_mu_sigma(int si, number &mu, number &sigma) const
reads the data for a subdomain from the data item
Definition em_material_impl.h:65
ConstSmartPtr< domain_type > domain() const
returns pointer to the domain
Definition em_material.h:123
void analyze_topology()
analyzes the conductor topology of the domain
Definition em_material_impl.h:240
domain_type::subset_handler_type subset_handler_type
subset handler type
Definition em_material.h:72
void close()
finalizes the object
Definition em_material_impl.h:109
ConstSmartPtr< subset_handler_type > subset_handler() const
constant access to the subset handler
Definition em_material.h:106
EMaterial(ConstSmartPtr< domain_type > domain)
Constructor.
Definition em_material_impl.h:46
void add(const char *name)
const char * name(size_t i) const
size_t size() const
SmartPtr< TSubsetHandler > subset_handler()
size_t num_subsets() const
NHT_VERTEX_NEIGHBORS
vector< string > TokenizeString(const char *str, const char delimiter=',')
void RemoveWhitespaceFromString(std::string &string)
#define UG_CATCH_THROW(msg)
#define UG_THROW(msg)
#define UG_LOG(msg)
double number
int DimensionOfSubset(const ISubsetHandler &sh, int si)
data item type
Definition em_material.h:215
number sigma
electric conductivity
Definition em_material.h:220
number mu
magnetic permeability
Definition em_material.h:219
SubsetGroup ssGrp
subset group
Definition em_material.h:217
std::string ssNames
subset names
Definition em_material.h:216