2020#include " ../include/boat_surface.h"
2121#include < deal.II/numerics/matrix_tools.h>
2222#include < deal.II/grid/grid_refinement.h>
23+ #include < BRepAdaptor_Curve.hxx>
2324
2425using namespace dealii ;
2526using namespace OpenCascade ;
@@ -1651,15 +1652,15 @@ void NumericalTowingTank::initialize_smoother()
16511652
16521653 curves.resize (7 );
16531654 on_curve_option.resize (7 );
1654- ref_locations .resize (7 );
1655+ smoothers_locations .resize (7 , NULL );
16551656
16561657 // parameters for front keel smoothing
16571658 base_points[0 ] = boat_model.PointFrontBot ;
16581659 moving_points[0 ] = boat_model.PointFrontTop ;
16591660 curves[0 ] = boat_model.equiv_keel_bspline ;
16601661 boundary_ids[0 ] = 30 ;
16611662 on_curve_option[0 ] = true ;
1662- ref_locations [0 ] = boat_model.reference_loc ;
1663+ smoothers_locations [0 ] = & boat_model.current_loc ;
16631664
16641665 // parameters for rear keel/left transom smoothing
16651666 if (boat_model.is_transom )
@@ -1669,7 +1670,7 @@ void NumericalTowingTank::initialize_smoother()
16691670 curves[1 ] = boat_model.left_transom_bspline ;
16701671 boundary_ids[1 ] = 32 ;
16711672 on_curve_option[1 ] = true ;
1672- ref_locations [1 ] = boat_model.reference_loc ;
1673+ smoothers_locations [1 ] = & boat_model.current_loc ;
16731674 }
16741675 else
16751676 {
@@ -1678,7 +1679,7 @@ void NumericalTowingTank::initialize_smoother()
16781679 curves[1 ] = boat_model.equiv_keel_bspline ;
16791680 boundary_ids[1 ] = 32 ;
16801681 on_curve_option[1 ] = true ;
1681- ref_locations [1 ] = boat_model.reference_loc ;
1682+ smoothers_locations [1 ] = & boat_model.current_loc ;
16821683 }
16831684
16841685 // parameters for rear keel/right transom smoothing
@@ -1689,7 +1690,7 @@ void NumericalTowingTank::initialize_smoother()
16891690 curves[2 ] = boat_model.right_transom_bspline ;
16901691 boundary_ids[2 ] = 37 ;
16911692 on_curve_option[2 ] = true ;
1692- ref_locations [2 ] = boat_model.reference_loc ;
1693+ smoothers_locations [2 ] = & boat_model.current_loc ;
16931694 }
16941695 else
16951696 {
@@ -1698,7 +1699,7 @@ void NumericalTowingTank::initialize_smoother()
16981699 curves[2 ] = boat_model.equiv_keel_bspline ;
16991700 boundary_ids[2 ] = 32 ;
17001701 on_curve_option[2 ] = true ;
1701- ref_locations [2 ] = boat_model.reference_loc ;
1702+ smoothers_locations [2 ] = & boat_model.current_loc ;
17021703 }
17031704
17041705 // parameters for front right water line smoothing
@@ -1764,7 +1765,7 @@ void NumericalTowingTank::initialize_smoother()
17641765 double smoother_tolerance = boat_model.boatWetLength *1e-3 ;
17651766 line_smoothers[i] = new LineSmoothing (smoothing_map_points,
17661767 curves[i],
1767- ref_locations [i],
1768+ smoothers_locations [i],
17681769 vector_dh,
17691770 boundary_dofs[i],
17701771 base_point_ids[i],
@@ -1786,6 +1787,7 @@ void NumericalTowingTank::update_smoother()
17861787 curves[0 ] = boat_model.equiv_keel_bspline ;
17871788 boundary_ids[0 ] = 30 ;
17881789 on_curve_option[0 ] = true ;
1790+ smoothers_locations[0 ] = &boat_model.current_loc ;
17891791
17901792 // parameters for rear keel/left transom smoothing
17911793 if (boat_model.is_transom )
@@ -1795,6 +1797,7 @@ void NumericalTowingTank::update_smoother()
17951797 curves[1 ] = boat_model.left_transom_bspline ;
17961798 boundary_ids[1 ] = 32 ;
17971799 on_curve_option[1 ] = true ;
1800+ smoothers_locations[1 ] = &boat_model.current_loc ;
17981801 }
17991802 else
18001803 {
@@ -1803,6 +1806,7 @@ void NumericalTowingTank::update_smoother()
18031806 curves[1 ] = boat_model.equiv_keel_bspline ;
18041807 boundary_ids[1 ] = 32 ;
18051808 on_curve_option[1 ] = true ;
1809+ smoothers_locations[1 ] = &boat_model.current_loc ;
18061810 }
18071811
18081812 // parameters for rear keel/right transom smoothing
@@ -1813,6 +1817,7 @@ void NumericalTowingTank::update_smoother()
18131817 curves[2 ] = boat_model.right_transom_bspline ;
18141818 boundary_ids[2 ] = 37 ;
18151819 on_curve_option[2 ] = true ;
1820+ smoothers_locations[2 ] = &boat_model.current_loc ;
18161821 }
18171822 else
18181823 {
@@ -1821,6 +1826,7 @@ void NumericalTowingTank::update_smoother()
18211826 curves[2 ] = boat_model.equiv_keel_bspline ;
18221827 boundary_ids[2 ] = 32 ;
18231828 on_curve_option[2 ] = true ;
1829+ smoothers_locations[2 ] = &boat_model.current_loc ;
18241830 }
18251831
18261832 // parameters for front right water line smoothing
@@ -2121,48 +2127,60 @@ vector_constraints.distribute(smoothing_map_points);
21212127// this takes care of the bow and stern nodes
21222128if (only_surf_smoothing == false )
21232129for (unsigned int k=3 ; k<7 ; ++k)
2124- {
2125- unsigned int i = moving_point_ids[k];
2126- // cout<<k<<" "<<i<<" "<<support_points[i]<<endl;
2127- {
2128- Point <3 > dP0 = support_points[i];
2129- Point <3 > dP;
2130- // this is the horizontal plane
2131- Handle (Geom_Plane) horPlane = new Geom_Plane (0 .,0 .,1 .,-dP0 (2 ));
2132- Handle (Geom_Curve) curve;
2133- if (boat_model.is_transom )
2130+ {
2131+ unsigned int i = moving_point_ids[k];
21342132 {
2135- if (k==3 || k==4 )
2136- curve = boat_model.equiv_keel_bspline ;
2137- else if (k == 6 )
2138- curve = boat_model.left_transom_bspline ;
2133+ Point <3 > dP0 = support_points[i];
2134+ Point <3 > dP;
2135+ // this is the horizontal plane
2136+ Handle (Geom_Plane) horPlane = new Geom_Plane (0 .,0 .,1 .,-dP0 (2 ));
2137+ Handle (Geom_Curve) curve;
2138+ TopLoc_Location L = boat_model.current_loc ;
2139+ TopLoc_Location L_inv = L.Inverted ();
2140+
2141+ horPlane->Transform (L_inv.Transformation ());
2142+ if (boat_model.is_transom )
2143+ {
2144+ if (k==3 || k==4 )
2145+ curve = boat_model.equiv_keel_bspline ;
2146+ else if (k == 6 )
2147+ curve = boat_model.left_transom_bspline ;
2148+ else
2149+ curve = boat_model.right_transom_bspline ;
2150+ }
21392151 else
2140- curve = boat_model.right_transom_bspline ;
2141- }
2142- else
2143- {
2144- curve = boat_model.equiv_keel_bspline ;
2145- }
2146- GeomAPI_IntCS Intersector (curve, horPlane);
2147- int npoints = Intersector.NbPoints ();
2148- AssertThrow ((npoints != 0 ), ExcMessage (" Keel or transom curve is not intersecting with horizontal plane!" ));
2149- // cout<<"Number of intersections: "<<npoints<<endl;
2150- double minDistance=1e7 ;
2151- gp_Pnt P;
2152- gp_Vec V1;
2153- double t,u,v;
2154- for (int j=0 ; j<npoints;++j)
2155- {
2156- Point<3 > inters = Pnt (Intersector.Point (j+1 ));
2157- Intersector.Parameters (j+1 ,u,v,t);
2152+ {
2153+ curve = boat_model.equiv_keel_bspline ;
2154+ }
21582155
2159- if (dP0.distance (inters) < minDistance)
2156+ TopoDS_Edge edge = BRepBuilderAPI_MakeEdge (curve);
2157+ edge.Location (L);
2158+ BRepAdaptor_Curve AC (edge);
2159+ gp_Pnt P;
2160+ gp_Vec V1;
2161+ GeomAPI_IntCS Intersector (curve, horPlane);
2162+ int npoints = Intersector.NbPoints ();
2163+
2164+ AssertThrow ((npoints != 0 ), ExcMessage (" Keel or transom curve is not intersecting with horizontal plane!" ));
2165+ double minDistance=1e7 ;
2166+ double t,u,v;
2167+ for (int j=0 ; j<npoints;++j)
21602168 {
2161- minDistance = dP0.distance (inters);
2162- dP = inters;
2163- curve->D1 (t,P,V1);
2169+ gp_Pnt int_point = Intersector.Point (j+1 );
2170+ int_point.Transform (L.Transformation ());
2171+ Point<3 > inters = Pnt (int_point);
2172+ Intersector.Parameters (j+1 ,u,v,t);
2173+ if (dP0.distance (inters) < minDistance)
2174+ {
2175+ minDistance = dP0.distance (inters);
2176+ dP = inters;
2177+ AC.D1 (t,P,V1);
2178+ }
21642179 }
2165- }
2180+ // cout<<"Check plane-curve intersection:"<<endl;
2181+ // cout<<"Origin: "<<dP0<<" Proj: "<<dP<<" dist: "<<minDistance<<endl;
2182+ // cout<<Pnt(P)<<endl;
2183+ /*
21662184 // here temporarily for kcs hull tests
21672185 if (minDistance > 0.5*boat_model.boatWetLength)
21682186 {
@@ -2189,12 +2207,12 @@ for (unsigned int k=3; k<7; ++k)
21892207 }
21902208 cout<<"New part two: "<<dP<<" | "<<V1.X()<<" "<<V1.Y()<<" "<<V1.Z()<<" | "<<dP0<<endl;
21912209 }
2192-
2210+ */
21932211 std::set<unsigned int > duplicates = double_nodes_set[i];
21942212 // duplicates.erase(i);
21952213 for (std::set<unsigned int >::iterator pos = duplicates.begin (); pos !=duplicates.end (); pos++)
21962214 {
2197- smoothing_map_points (3 *(*pos)) = dP (0 )-ref_points[3 *(*pos)](0 );
2215+ smoothing_map_points (3 *(*pos)) = dP (0 )-ref_points[3 *(*pos)](0 );
21982216 smoothing_map_points (3 *(*pos)+1 ) = dP (1 )-ref_points[3 *(*pos)](1 );
21992217 smoothing_map_points (3 *(*pos)+2 ) = dP (2 )-ref_points[3 *(*pos)](2 );
22002218 edges_tangents[3 *(*pos)] = V1.X ();
@@ -2225,7 +2243,6 @@ for (unsigned int i=0; i<vector_dh.n_dofs(); ++i)
22252243 }
22262244
22272245// ////////////////////////////////////////
2228-
22292246 // line smoothing on keel/transom is performed here and modifies smoothing_map_points
22302247 // it ONLY moves nodes on the LEFT side of the keel
22312248for (unsigned int i=0 ; i<3 ; ++i)
@@ -2249,7 +2266,6 @@ for(unsigned int i=0; i<3; ++i)
22492266
22502267 }
22512268 }
2252-
22532269 // line smoothing on water_lines is performed here and modifies smoothing_map_points
22542270 // it ONLY moves nodes on the water that are also near_boat
22552271if (only_surf_smoothing == false )
0 commit comments