summaryrefslogtreecommitdiff
path: root/src/NLPlate/NLPlate_NLPlate.cxx
blob: 474ec08c5b64dbae937c31210ec450d319b9d36b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// File:	NLPlate_NLPlate.cxx
// Created:	Thu Apr  9 18:33:41 1998
// Author:	Andre LIEUTIER
//		<alr@sgi63>


#include <math_Matrix.hxx>
#include <math_Vector.hxx>
#include <math_Gauss.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>

#include <Plate_D1.hxx>
#include <Plate_D2.hxx>
#include <Plate_D3.hxx>
#include <Plate_Plate.hxx>
#include <Plate_PinpointConstraint.hxx>
#include <Plate_FreeGtoCConstraint.hxx>

#include <NLPlate_StackIteratorOfStackOfPlate.hxx>

#include <NLPlate_NLPlate.ixx>


NLPlate_NLPlate::NLPlate_NLPlate(const Handle(Geom_Surface)& InitialSurface) :
 myInitialSurface(InitialSurface),OK(Standard_False) {}
//=======================================================================

 void NLPlate_NLPlate::Load(const Handle(NLPlate_HGPPConstraint)& GConst) 
{
  if(!GConst.IsNull()) myHGPPConstraints.Append(GConst);
  OK = Standard_False;
}

//=======================================================================
//function : Solve
//purpose  : 
//=======================================================================
 void NLPlate_NLPlate::Solve(const Standard_Integer ord, const Standard_Integer InitialConsraintOrder) 
{
  Standard_Integer maxOrder = MaxActiveConstraintOrder();
  Standard_Integer ordre = ord;
  if(ordre<maxOrder+2) ordre = maxOrder+2;

  for(Standard_Integer iterOrder=InitialConsraintOrder;iterOrder<=maxOrder;iterOrder++)
    {
     if(!Iterate(iterOrder,ordre+iterOrder-maxOrder))
       {
	OK = Standard_False;
	break;
       }
    }
  OK = Standard_True;
}
//=======================================================================
//function : Solve2
//purpose  : 
//=======================================================================
 void NLPlate_NLPlate::Solve2(const Standard_Integer ord, const Standard_Integer InitialConsraintOrder) 
{
  Standard_Integer maxOrder = MaxActiveConstraintOrder();
  Standard_Integer ordre = ord;
  if(ordre<maxOrder+2) ordre = maxOrder+2;
  if(Iterate(0,ord)) 
    {
      mySOP.ChangeTop().SetPolynomialPartOnly(Standard_True);
      ConstraintsSliding();
    }
      

  for(Standard_Integer iterOrder=InitialConsraintOrder;iterOrder<=maxOrder;iterOrder++)
    {
     if(!Iterate(iterOrder,ordre+iterOrder-maxOrder))
       {
	OK = Standard_False;
	break;
       }
    }
  OK = Standard_True;
}

//=======================================================================
//function : IncrementalSolve
//purpose  : 
//=======================================================================
 void NLPlate_NLPlate::IncrementalSolve(const Standard_Integer ord, const Standard_Integer InitialConsraintOrder,
			     const Standard_Integer NbIncrements, const Standard_Boolean UVSliding) 
{
  Standard_Integer maxOrder = MaxActiveConstraintOrder();
  Standard_Integer ordre = ord;
  if(ordre<maxOrder+2) ordre = maxOrder+2;
  Standard_Real IncrementalLoad = 1.;

  for(Standard_Integer increment=0;increment < NbIncrements;increment++)
    {
      IncrementalLoad = 1./Standard_Real(NbIncrements-increment);
//      for(Standard_Integer iterOrder=InitialConsraintOrder;iterOrder<=maxOrder;iterOrder++)
      Standard_Integer iterOrder=maxOrder;
	{
	  if(!Iterate(iterOrder,ordre+iterOrder-maxOrder,IncrementalLoad))
	    {
	      OK = Standard_False;
	      return;
	    }
	}
      if(UVSliding) ConstraintsSliding();
    }
  OK = Standard_True;
}

//=======================================================================
 Standard_Boolean NLPlate_NLPlate::IsDone() const
{
  return OK;
}
//=======================================================================

 void NLPlate_NLPlate::destroy() 
{
  Init();
}
//=======================================================================

 void NLPlate_NLPlate::Init() 
{
  mySOP.Clear();
  myHGPPConstraints.Clear();
}
//=======================================================================

 gp_XYZ NLPlate_NLPlate::Evaluate(const gp_XY& point2d) const
{
  return EvaluateDerivative(point2d,0,0);
}
//=======================================================================

 gp_XYZ NLPlate_NLPlate::EvaluateDerivative(const gp_XY& point2d,const Standard_Integer iu,const Standard_Integer iv) const
{
  gp_XYZ Value(0.,0.,0.);
  if((iu==0)&&(iv==0))
    Value = myInitialSurface->Value(point2d.X(),point2d.Y()).XYZ();
  else
    Value = myInitialSurface->DN(point2d.X(),point2d.Y(),iu,iv).XYZ();

  for(NLPlate_StackIteratorOfStackOfPlate SI(mySOP);SI.More();SI.Next())
    {
      if(SI.Value().IsDone())
	Value += SI.Value().EvaluateDerivative(point2d,iu,iv);
    }
  return Value;
}
//=======================================================================

 Standard_Integer NLPlate_NLPlate::Continuity() const
{
  Standard_Integer cont ;
  for( cont=-1; cont<10;cont++)
    {
      if(!(myInitialSurface->IsCNu(cont+1)&&myInitialSurface->IsCNv(cont+1)))break;
    }
  for(NLPlate_StackIteratorOfStackOfPlate SI(mySOP);SI.More();SI.Next())
    {
      if((SI.Value().IsDone())&&(cont > SI.Value().Continuity())) cont = SI.Value().Continuity();
    }
  return cont;
}
//=======================================================================

Standard_Boolean NLPlate_NLPlate::Iterate(const Standard_Integer ConstraintOrder,
const Standard_Integer ResolutionOrder,
const Standard_Real IncrementalLoading) 
{
  Plate_Plate EmptyPlate;
  mySOP.Push(EmptyPlate);
  Plate_Plate &TopP = mySOP.ChangeTop();
  for(Standard_Integer index =1; index <= myHGPPConstraints.Length(); index++)
    {
      const Handle(NLPlate_HGPPConstraint) &HGPP = myHGPPConstraints(index);
      Standard_Integer Order = HGPP->ActiveOrder();
      if(ConstraintOrder<Order) Order = ConstraintOrder;
      const gp_XY &UV = HGPP->UV();
      
      if((Order >=0)&& HGPP->IsG0())
	{
	  if(HGPP->IncrementalLoadAllowed())
	    TopP.Load(Plate_PinpointConstraint(UV, (HGPP->G0Target()-Evaluate(UV))*IncrementalLoading));
	  else
	    TopP.Load(Plate_PinpointConstraint(UV, HGPP->G0Target()-Evaluate(UV)));
	}
      
      if((IncrementalLoading != 1.) && HGPP->IncrementalLoadAllowed() && (Order>=1))
	{
	  switch(Order)
	    {
	    case 1:
	      {
		Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1));
		TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),IncrementalLoading,HGPP->Orientation()));
	      }
	      break;
	    case 2:
	      {
		Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1));
		Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2));
		TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target(),
						   IncrementalLoading,HGPP->Orientation()));
	      }
	      break;
	    case 3:
	      {
		Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1));
		Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2));
		Plate_D3 D3S(EvaluateDerivative(UV,3,0),EvaluateDerivative(UV,2,1),
			     EvaluateDerivative(UV,1,2),EvaluateDerivative(UV,0,3));
		TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target(),D3S,HGPP->G3Target(),
						   IncrementalLoading,HGPP->Orientation()));
	      }
	      break;
	    default:
	      break;
	    }
	}
      else
	{
	  switch(Order)
	    {
	    case 1:
	      {
		Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1));
		TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target()));
	      }
	      break;
	    case 2:
	      {
		Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1));
		Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2));
		TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target()));
	      }
	      break;
	    case 3:
	      {
		Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1));
		Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2));
		Plate_D3 D3S(EvaluateDerivative(UV,3,0),EvaluateDerivative(UV,2,1),
			     EvaluateDerivative(UV,1,2),EvaluateDerivative(UV,0,3));
		TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target(),D3S,HGPP->G3Target()));
	      }
	      break;
	    default:
	      break;
	    }
	}
    }
  
  TopP.SolveTI(ResolutionOrder);
  if(!TopP.IsDone())
    {
      mySOP.Pop();
      return Standard_False;
    }
  else
    return Standard_True;
}
//=======================================================================

 void NLPlate_NLPlate::ConstraintsSliding(const Standard_Integer NbIterations) 
{
  for(Standard_Integer index =1; index <= myHGPPConstraints.Length(); index++)
    {
      const Handle(NLPlate_HGPPConstraint) &HGPP = myHGPPConstraints(index);
      if(HGPP->UVFreeSliding() && HGPP->IsG0())
	{
	  gp_XY UV = HGPP->UV();
	  gp_XYZ P0 = Evaluate(UV);
	  const gp_XYZ P1 = HGPP->G0Target();
	  for(Standard_Integer iter=1;iter<=NbIterations;iter++)
	    {
	      // on itere au premier ordre, ce qui suffit si on est assez pres de la surface ??
	      gp_XYZ DP = P1 - P0;
	      gp_XYZ Du = EvaluateDerivative(UV,1,0);
	      gp_XYZ Dv = EvaluateDerivative(UV,0,1);
	      math_Matrix mat(0,1,0,1);
	      mat(0,0) = Du*Du;
	      mat(0,1) = Du*Dv;
	      mat(1,0) = Du*Dv;
	      mat(1,1) = Dv*Dv;
	      math_Gauss gauss(mat);
	      if(!gauss.IsDone()) break;

	      math_Vector vec(0,1);
	      vec(0) = Du*DP;
	      vec(1) = Dv*DP;
	      math_Vector sol(0,1);
	      gauss.Solve(vec,sol);
	      UV.SetX(UV.X()+sol(0));
	      UV.SetY(UV.Y()+sol(1));
	      P0 = Evaluate(UV);
	    }
	  HGPP->SetUV(UV);
	}
    }
}

//=======================================================================

 Standard_Integer NLPlate_NLPlate::MaxActiveConstraintOrder() const
{
  Standard_Integer MaxOrder = -1;
  for(Standard_Integer index =1; index <= myHGPPConstraints.Length(); index++)
    {
      Standard_Integer CAOrder = myHGPPConstraints(index)->ActiveOrder();
      if(CAOrder > MaxOrder) MaxOrder = CAOrder;
    }
  return MaxOrder;
}