28 class gsXml< gsBoundaryConditions<T> >
32 typedef gsBoundaryConditions<T> Object;
34 GSXML_COMMON_FUNCTIONS(Object);
35 static std::string tag () {
return "boundaryConditions"; }
36 static std::string type () {
return ""; }
38 GSXML_GET_POINTER(Object);
40 static void get_into(gsXmlNode * node, Object & result)
43 "Something went wrong. Expected tag "<< tag());
45 std::istringstream str;
46 std::map<int, int> ids;
49 const int mp_index = atoi(node->first_attribute(
"multipatch")->value());
50 gsXmlNode* toplevel = node->parent();
51 std::vector< patchSide > allboundaries;
52 for (gsXmlNode * child = node->first_node(
"bc"); child;
53 child = child->next_sibling(
"bc"))
55 std::map<int, int> tmp_ids;;
57 const gsXmlAttribute * att_name = child->first_attribute(
"name");
60 gsXmlNode* mp_node =
searchId(mp_index, toplevel);
62 "No Multipatch with Id "<<mp_index<<
" found in the XML data.");
64 gsXmlNode * tmp = mp_node->first_node(
"patches");
65 std::istringstream tmp_str ;
66 tmp_str.str( tmp->value() );
68 if ( ! strcmp( tmp->first_attribute(
"type")->value(),
"id_range") )
71 gsGetInt(tmp_str, first);
72 gsGetInt(tmp_str, last);
73 for (
int i = first; i<=last; ++i )
74 tmp_ids[i] = i - first;
76 else if ( ! strcmp( tmp->first_attribute(
"type")->value(),
"id_index") )
79 for (
int pindex; gsGetInt(tmp_str, pindex);)
80 tmp_ids[pindex] = c++;
84 gsWarn<<
"Unknown tag in XML multipatch object.\n";
87 for (gsXmlNode * ch= mp_node->first_node(
"boundary"); ch;
88 ch = ch->next_sibling(
"boundary"))
90 std::vector< patchSide > tmp_boundaries;
93 getBoundaries(ch, tmp_ids, tmp_boundaries);
94 allboundaries.insert( allboundaries.end(), tmp_boundaries.begin(), tmp_boundaries.end() );
129 std::map<int, typename gsFunctionExpr<T>::Ptr> function_map{};
130 for (gsXmlNode* child = node->first_node(
"Function"); child;
131 child = child->next_sibling(
"Function")) {
132 const int function_index =
133 atoi(child->first_attribute(
"index")->value());
134 function_map[function_index] =
136 internal::gsXml<gsFunctionExpr<T> >::get_into(
137 child, *function_map[function_index]);
141 std::vector<patchSide> boundaries;
142 for (gsXmlNode* child = node->first_node(
"bc"); child;
143 child = child->next_sibling(
"bc")) {
144 const int uIndex = atoi(child->first_attribute(
"unknown")->value());
145 const int fIndex = atoi(child->first_attribute(
"function")->value());
147 const gsXmlAttribute* comp = child->first_attribute(
"component");
149 if (NULL != comp) cIndex = atoi(comp->value());
151 const gsXmlAttribute* att_ispar =
152 child->first_attribute(
"parametric");
154 if (NULL != att_ispar) ispar = atoi(att_ispar->value());
156 const gsXmlAttribute* att_name = child->first_attribute(
"name");
157 if (NULL != att_name) {
159 std::string name = att_name->value();
160 for (
typename std::vector<patchSide>::const_iterator it =
161 allboundaries.begin();
162 it != allboundaries.end(); it++)
163 if (it->label() == name) boundaries.push_back(*it);
165 getBoundaries(child, ids, boundaries);
167 if (boundaries.size() == 0) {
168 gsWarn <<
"Boundary condition without boundary to apply to. The"
169 " following bc will be unused\n"
170 << *child << std::endl;
173 const gsXmlAttribute* bcat = child->first_attribute(
"type");
175 const char* bctype = bcat->value();
176 for (std::vector<patchSide>::const_iterator it = boundaries.begin();
177 it != boundaries.end(); ++it)
178 result.add(it->patch, it->side(), bctype, function_map[fIndex], uIndex,
183 for (gsXmlNode * child = node->first_node(
"cv"); child;
184 child = child->next_sibling(
"cv"))
187 str.str(child->value());
191 const gsXmlAttribute * unk = child->first_attribute(
"unknown");
194 uIndex = atoi( unk->value() );
197 const gsXmlAttribute * comp = child->first_attribute(
"component");
200 cIndex = atoi( comp->value() );
202 const int cornIndex = atoi(child->first_attribute(
"corner")->value());
203 int pIndex = atoi(child->first_attribute(
"patch")->value());
205 result.addCornerValue(cornIndex, val, pIndex, uIndex, cIndex);
209 static gsXmlNode * put(
const Object & obj, gsXmlTree & data)
219 BCs->append_attribute(multi);
222 typedef typename gsBoundaryConditions<T>::const_bciterator bctype_it;
223 typedef typename Object::const_iterator bc_it;
225 std::vector<typename gsFunctionSet<T>::Ptr> fun;
227 typedef typename std::vector<const boundary_condition<T>*> bctype_vec;
228 typedef typename std::map<int, bctype_vec> bctype_map;
229 std::map<std::string, bctype_map> fi;
231 for (bctype_it it = obj.beginAll(); it != obj.endAll(); ++it)
233 std::string label = it->first;
235 for (bc_it bc = it->second.begin(); bc != it->second.end(); ++bc)
237 typename gsFunctionSet<T>::Ptr ptr = bc->function();
238 bool contains = std::find(fun.begin(), fun.end(), ptr)
244 int index = std::find(fun.begin(), fun.end(), ptr)
248 std::vector<const boundary_condition<T>*> vec = map[index];
249 const boundary_condition<T>* b = &(*bc);
253 std::pair<std::string, bctype_map> pair(label, map);
258 typedef typename std::vector<typename gsFunctionSet<T>::Ptr>::const_iterator fun_it;
259 for (fun_it fit = fun.begin(); fit != fun.end(); ++fit)
261 gsXmlNode * ff = putFunctionToXml<T>(*fit, data, count);
262 BCs->append_node(ff);
267 typedef typename std::map<std::string, bctype_map>::const_iterator bctype_map_it;
268 typedef typename std::map<int, bctype_vec>::const_iterator bctype_iv_it;
269 typedef typename bctype_vec::const_iterator bctype_vec_it;
272 for (bctype_map_it it = fi.begin(); it != fi.end(); ++it)
274 std::string label = it->first;
276 bctype_map map = it->second;
278 for (bctype_iv_it bcV = map.begin(); bcV != map.end(); ++bcV)
280 int index = bcV->first;
281 bctype_vec vec = bcV->second;
289 bcNode->append_attribute(typeNode);
290 bcNode->append_attribute(indexNode);
292 std::ostringstream oss;
293 for (bctype_vec_it bc = vec.begin(); bc != vec.end(); ++bc)
295 const boundary_condition<T> b = (**bc);
301 "unknown", b.m_unknown, data);
303 b.unkComponent(), data);
304 bcNode->append_attribute(componentNode);
305 bcNode->append_attribute(unknownNode);
312 oss << b.ps.patch <<
" " << b.ps.m_index;
314 char * value = data.allocate_string(oss.str().c_str());
315 bcNode->value(value);
316 BCs->append_node(bcNode);
320 typename gsBoundaryConditions<T>::const_citerator ci;
321 for (ci = obj.cornerValues().begin(); ci != obj.cornerValues().end();
324 corner_value<T> c = *ci;
333 c.corner.m_index, data);
334 cvNode->append_attribute(unknownNode);
335 cvNode->append_attribute(componentNode);
336 cvNode->append_attribute(patchNode);
337 cvNode->append_attribute(cornerNode);
338 std::ostringstream oss;
340 char * value = data.allocate_string(oss.str().c_str());
341 cvNode->value(value);
343 BCs->append_node(cvNode);
Provides declaration of FunctionExpr class.
Provides declaration of ConstantFunction class.
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
gsXmlNode * searchId(const int id, gsXmlNode *root, const char *tag_name=NULL, const bool print_warning=true)
Definition: gsXml.h:254
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Provides implementation of generic XML functions.
#define gsWarn
Definition: gsDebug.h:50
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54
An std::vector with sorting capabilities.
Provides declaration of input/output XML utilities struct.
shared_ptr< T > make_shared(T *x)
Definition: gsMemory.h:181