44
44
#include <iostream> // @@ debug
45
45
#include <fstream>
46
46
#include <iterator> // @@ debug - remove
47
+ #include <string.h>
47
48
//#include <chrono> // @@ debug
48
49
#include <set>
49
50
#include <tuple>
@@ -716,10 +717,12 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
716
717
// Make a copy of the initial mesh
717
718
Mesh2D mesh2 = mesh_ ;
718
719
720
+ bool refined ;
719
721
const auto indices = // tuple<int, int, int, int>
720
- LRSplineUtils ::refine_mesh (d , fixed_val , start , end , mult , absolute ,
721
- degree (d ), knot_tol_ , mesh_ ,
722
- (d == XFIXED ) ? bsplinesuni1_ : bsplinesuni2_ );
722
+ LRSplineUtils ::refine_mesh (d , fixed_val , start , end , mult ,
723
+ absolute , degree (d ), knot_tol_ , mesh_ ,
724
+ (d == XFIXED ) ? bsplinesuni1_ : bsplinesuni2_ ,
725
+ refined );
723
726
724
727
#ifdef DEBUG
725
728
std ::ofstream of2 ("mesh1.eps" );
@@ -788,6 +791,22 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
788
791
#ifdef DEBUG
789
792
elems_affected .push_back (curr_el );
790
793
#endif
794
+ // if (d == XFIXED)
795
+ // {
796
+ // double u1 = curr_el->umin();
797
+ // double u2 = curr_el->umax();
798
+ // if ((u2 - fixed_val > 0.55*(u2-u1) || fixed_val - u1 > 0.55*(u2-u1)) &&
799
+ // u2-fixed_val > 0.0001 && fixed_val-u1 > 0.0001)
800
+ // std::cout << "Unbalanced element, 1. par: " << fixed_val << " in [" << u1 << "," << u2 << "]" << std::endl;
801
+ // }
802
+ // else
803
+ // {
804
+ // double v1 = curr_el->vmin();
805
+ // double v2 = curr_el->vmax();
806
+ // if ((v2 - fixed_val > 0.55*(v2-v1) || fixed_val - v1 > 0.55*(v2-v1)) &&
807
+ // v2-fixed_val > 0.0001 && fixed_val-v1 > 0.0001)
808
+ // std::cout << "Unbalanced element, 2. par: " << fixed_val << " in [" << v1 << "," << v2 << "]" << std::endl;
809
+ // }
791
810
}
792
811
}
793
812
vector < LRBSpline2D * > bsplines_affected (all_bsplines .begin (), all_bsplines .end ());
@@ -891,7 +910,7 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
891
910
// combination of objects and pointers will not work.
892
911
LRSplineUtils ::iteratively_split2 (bsplines_affected , mesh_ ,
893
912
bsplines_ , domain ,
894
- bsplinesuni1_ , bsplinesuni2_ );
913
+ bsplinesuni1_ , bsplinesuni2_ , true );
895
914
// bsplinesuni1_, iu1, iu2,
896
915
// bsplinesuni2_, iv1, iv2);
897
916
@@ -999,8 +1018,7 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
999
1018
1000
1019
#ifdef DEBUG
1001
1020
if (it2 == emap_ .end ())
1002
- int stop_break = 1 ;
1003
- //std::cout << "LRSplineSurface::refine : Element not found" << std::endl;
1021
+ std ::cout << "LRSplineSurface::refine : Element not found" << std ::endl ;
1004
1022
#endif
1005
1023
}
1006
1024
@@ -1031,14 +1049,9 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
1031
1049
it2 -> second -> getOutsidePoints (data_points , d , sort_in_u );
1032
1050
it2 -> second -> getOutsideSignificantPoints (significant_points ,
1033
1051
d , sort_in_u_significant );
1034
- it2 -> second -> getOutsideGhostPoints (ghost_points , d ,
1052
+ it2 -> second -> getOutsideGhostPoints (ghost_points , d ,
1035
1053
sort_in_u_ghost );
1036
1054
pt_del = it2 -> second -> getNmbValPrPoint ();
1037
- // it2->second->getAccuracyInfo(averr, maxerr, nmbout);
1038
- // accerr = it2->second->getAccumulatedError();
1039
-
1040
- // Update accuracy statistices in element
1041
- it2 -> second -> updateAccuracyInfo ();
1042
1055
1043
1056
// Update supported LRBsplines
1044
1057
for (size_t kb = 0 ; kb < bsplines_affected .size (); ++ kb )
@@ -1079,17 +1092,14 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
1079
1092
if (data_points .size () > 0 )
1080
1093
elem -> addDataPoints (data_points .begin (), data_points .end (),
1081
1094
sort_in_u , pt_del );
1082
- if (significant_points .size () > 0 )
1083
- elem -> addSignificantPoints (significant_points .begin (),
1084
- significant_points .end (),
1085
- sort_in_u_significant , pt_del );
1095
+ if (significant_points .size () > 0 )
1096
+ elem -> addSignificantPoints (significant_points .begin (),
1097
+ significant_points .end (),
1098
+ sort_in_u_significant , pt_del );
1099
+
1086
1100
if (ghost_points .size () > 0 )
1087
1101
elem -> addGhostPoints (ghost_points .begin (), ghost_points .end (),
1088
1102
sort_in_u_ghost , pt_del );
1089
- //elem->setAccuracyInfo(accerr, averr, maxerr, nmbout); // Not exact info as the
1090
- // element has been split
1091
- elem -> updateAccuracyInfo (); // Accuracy statistic in element
1092
-
1093
1103
emap_ .insert (std ::make_pair (key , std ::move (elem )));
1094
1104
//auto it3 = emap_.find(key);
1095
1105
@@ -1107,6 +1117,22 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
1107
1117
#endif
1108
1118
}
1109
1119
1120
+ struct refval
1121
+ {
1122
+ refval (int val , int m )
1123
+ {
1124
+ kval = val ;
1125
+ mult = m ;
1126
+ }
1127
+ int kval , mult ;
1128
+ };
1129
+
1130
+ int compare_refs_sf (refval r1 , refval r2 )
1131
+ {
1132
+ return (r1 .kval < r2 .kval );
1133
+ }
1134
+
1135
+
1110
1136
//==============================================================================
1111
1137
void LRSplineSurface ::refine (const vector < Refinement2D > & refs ,
1112
1138
bool absolute )
@@ -1123,7 +1149,14 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
1123
1149
int stop_break = 1 ;
1124
1150
}
1125
1151
#endif
1152
+ // Collect B-splines affected by the refinements
1153
+ vector < LRBSpline2D * > affected ;
1154
+ LRSplineUtils ::get_affected_bsplines (refs , emap_ , knot_tol_ , mesh_ ,
1155
+ affected );
1156
+
1157
+ vector < refval > u_refs , v_refs ;
1126
1158
for (size_t i = 0 ; i != refs .size (); ++ i ) {
1159
+ bool refined ;
1127
1160
const Refinement2D & r = refs [i ];
1128
1161
const auto indices = // tuple<int, int, int, int>
1129
1162
LRSplineUtils ::refine_mesh (r .d ,
@@ -1135,51 +1168,109 @@ void LRSplineSurface::refine(Direction2D d, double fixed_val, double start,
1135
1168
degree (r .d ),
1136
1169
knot_tol_ ,
1137
1170
mesh_ ,
1138
- (r .d == XFIXED ) ? bsplinesuni1_ : bsplinesuni2_ );
1171
+ (r .d == XFIXED ) ? bsplinesuni1_ : bsplinesuni2_ ,
1172
+ refined );
1139
1173
1140
- // Not efficient
1141
- int fixed_ix = get < 1 > (indices ); // Index of fixed_val in global knot vector.
1142
- int last_ix =
1143
- BSplineUniUtils ::last_overlapping_bsplineuni (fixed_ix ,
1144
- (r .d == XFIXED ) ? bsplinesuni1_ : bsplinesuni2_ );
1145
-
1174
+ if (!refined )
1175
+ continue ;
1176
+ refval curr (r .kval , r .multiplicity );
1177
+ size_t kr ;
1146
1178
if (r .d == XFIXED )
1179
+ {
1180
+ for (kr = 0 ; kr < u_refs .size (); ++ kr )
1181
+ if (u_refs [kr ].kval == curr .kval &&
1182
+ u_refs [kr ].mult == curr .mult )
1183
+ break ;
1184
+ if (kr == u_refs .size ())
1185
+ u_refs .push_back (curr );
1186
+ }
1187
+ else if (r .d == YFIXED )
1188
+ {
1189
+ for (kr = 0 ; kr < v_refs .size (); ++ kr )
1190
+ if (v_refs [kr ].kval == curr .kval &&
1191
+ v_refs [kr ].mult == curr .mult )
1192
+ break ;
1193
+ if (kr == v_refs .size ())
1194
+ v_refs .push_back (curr );
1195
+ }
1196
+ }
1197
+
1198
+ if (u_refs .size () + v_refs .size () == 0 )
1199
+ return ; // Mesh rectangles already existing
1200
+
1201
+ //std::cout << "Post refine mesh" << std::endl;
1202
+ std ::sort (u_refs .begin (), u_refs .end (), compare_refs_sf );
1203
+ std ::sort (v_refs .begin (), v_refs .end (), compare_refs_sf );
1204
+
1205
+ for (int ki = (int )u_refs .size ()- 1 ; ki >=0 ; -- ki )
1206
+ {
1207
+ int kval = u_refs [ki ].kval ;
1208
+ int fixed_ix = Mesh2DUtils ::last_nonlarger_knotvalue_ix (mesh_ , XFIXED , kval );
1209
+
1210
+ int last_ix =
1211
+ BSplineUniUtils ::last_overlapping_bsplineuni (fixed_ix , bsplinesuni1_ );
1212
+
1147
1213
LRSplineUtils ::split_univariate (bsplinesuni1_ , last_ix , fixed_ix ,
1148
- (absolute ) ? r .multiplicity : 1 );
1149
- else
1214
+ absolute ? u_refs [ki ].mult : 1 );
1215
+ }
1216
+
1217
+ for (int ki = (int )v_refs .size ()- 1 ; ki >=0 ; -- ki )
1218
+ {
1219
+ int kval = v_refs [ki ].kval ;
1220
+ int fixed_ix = Mesh2DUtils ::last_nonlarger_knotvalue_ix (mesh_ , YFIXED , kval );
1221
+
1222
+ int last_ix =
1223
+ BSplineUniUtils ::last_overlapping_bsplineuni (fixed_ix , bsplinesuni2_ );
1224
+
1150
1225
LRSplineUtils ::split_univariate (bsplinesuni2_ , last_ix , fixed_ix ,
1151
- (absolute ) ? r .multiplicity : 1 );
1152
- }
1226
+ absolute ? v_refs [ki ].mult : 1 );
1227
+ }
1228
+
1229
+ // // Not efficient
1230
+ // int fixed_ix = get<1>(indices); // Index of fixed_val in global knot vector.
1231
+ // int last_ix =
1232
+ // BSplineUniUtils::last_overlapping_bsplineuni(fixed_ix,
1233
+ // (r.d == XFIXED) ? bsplinesuni1_ : bsplinesuni2_);
1234
+
1235
+ // if (r.d == XFIXED)
1236
+ // LRSplineUtils::split_univariate(bsplinesuni1_, last_ix, fixed_ix,
1237
+ // (absolute) ? r.multiplicity : 1);
1238
+ // else
1239
+ // LRSplineUtils::split_univariate(bsplinesuni2_, last_ix, fixed_ix,
1240
+ // (absolute) ? r.multiplicity : 1);
1241
+ // }
1153
1242
1154
1243
1155
1244
//std::wcout << "Preparing for iterative splitting." << std::endl;
1156
- vector < unique_ptr < LRBSpline2D > > affected ;
1157
- affected .reserve (bsplines_ .size ());
1158
- // for_each(bsplines_.begin(), bsplines_.end(), [&](const BSplineMap::value_type& b) {
1159
- for (auto it = bsplines_ .begin (); it != bsplines_ .end (); ++ it )
1160
- {
1161
- // @@@ VSK. This is maybe the place to remove element information from the bsplines?
1162
- unique_ptr < LRBSpline2D > ptr = std ::move (it -> second );
1163
- affected .emplace_back (std ::move (ptr ));//b.second);
1164
- };
1245
+ //vector<unique_ptr<LRBSpline2D> > affected;
1246
+ // vector<LRBSpline2D*> affected;
1247
+ // affected.reserve(bsplines_.size());
1248
+ // // for_each(bsplines_.begin(), bsplines_.end(), [&](const BSplineMap::value_type& b) {
1249
+ // for (auto it = bsplines_.begin(); it!= bsplines_.end(); ++it)
1250
+ // {
1251
+ // affected.push_back((*it).second.get());
1252
+ // // @@@ VSK. This is maybe the place to remove element information from the bsplines?
1253
+ // // unique_ptr<LRBSpline2D> ptr = std::move(it->second);
1254
+ // // affected.emplace_back(std::move(ptr));//b.second);
1255
+ // };
1165
1256
1166
1257
// @@@ VSK. In this case, we should not bother about splitting elements. They will
1167
1258
// be regenerated later. Thus, the bsplines should NOT be updated with elements during
1168
1259
// splitting
1169
1260
// The bsplines should not have any pointers to elements. They will be set later
1170
1261
//std::wcout << "Iteratively splitting." << std::endl;
1171
1262
1172
- LRSplineUtils ::iteratively_split (affected , mesh_ ,
1173
- bsplinesuni1_ , bsplinesuni2_ );
1174
- bsplines_ .clear ();
1263
+ LRSplineUtils ::iteratively_split2 (affected , mesh_ , bsplines_ , NULL ,
1264
+ bsplinesuni1_ , bsplinesuni2_ , false );
1265
+ // bsplines_.clear();
1175
1266
1176
1267
//std::wcout << "Splitting finished, now inserting resulting functions" << std::endl;
1177
1268
// The bsplines are checked for duplicates and inserted in the global bspline map
1178
1269
// for_each(affected.begin(), affected.end(), [&](unique_ptr<LRBSpline2D> b) {
1179
- for (auto it = affected .begin (); it != affected .end (); ++ it )
1180
- {
1181
- LRSplineUtils ::insert_basis_function (* it , mesh_ , bsplines_ );
1182
- };
1270
+ // for (auto it = affected.begin(); it != affected.end(); ++it)
1271
+ // {
1272
+ // LRSplineUtils::insert_basis_function(*it, mesh_, bsplines_);
1273
+ // };
1183
1274
1184
1275
#if 0 //ndef NDEBUG
1185
1276
{
@@ -1218,7 +1309,6 @@ for (auto it = affected.begin(); it != affected.end(); ++it)
1218
1309
1219
1310
}
1220
1311
1221
-
1222
1312
//==============================================================================
1223
1313
void LRSplineSurface ::addSurface (const LRSplineSurface & other_sf , double fac )
1224
1314
//==============================================================================
@@ -3573,6 +3663,7 @@ LRSplineSurface::collect_basis(int from_u, int to_u,
3573
3663
return b_splines ;
3574
3664
}
3575
3665
3666
+
3576
3667
//===========================================================================
3577
3668
void
3578
3669
LRSplineSurface ::checkSupport (LRBSpline2D * basis ) const
0 commit comments