-
Notifications
You must be signed in to change notification settings - Fork 0
/
axisym_solid_traction_elements.h
executable file
·2978 lines (2387 loc) · 98.9 KB
/
axisym_solid_traction_elements.h
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//LIC// ====================================================================
//LIC// This file forms part of oomph-lib, the object-oriented,
//LIC// multi-physics finite-element library, available
//LIC// at http://www.oomph-lib.org.
//LIC//
//LIC// Version 0.90. August 3, 2009.
//LIC//
//LIC// Copyright (C) 2006-2009 Matthias Heil and Andrew Hazel
//LIC//
//LIC// This library is free software; you can redistribute it and/or
//LIC// modify it under the terms of the GNU Lesser General Public
//LIC// License as published by the Free Software Foundation; either
//LIC// version 2.1 of the License, or (at your option) any later version.
//LIC//
//LIC// This library is distributed in the hope that it will be useful,
//LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
//LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//LIC// Lesser General Public License for more details.
//LIC//
//LIC// You should have received a copy of the GNU Lesser General Public
//LIC// License along with this library; if not, write to the Free Software
//LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
//LIC// 02110-1301 USA.
//LIC//
//LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
//LIC//
//LIC//====================================================================
//Header file for elements that are used to apply surface loads to
//the equations of elasticity
#ifndef OOMPH_AXISYMM_SOLID_TRACTION_ELEMENTS_HEADER
#define OOMPH_AXISYMM_SOLID_TRACTION_ELEMENTS_HEADER
// Config header generated by autoconfig
#ifdef HAVE_CONFIG_H
#include <oomph-lib-config.h>
#endif
// OOMPH-LIB headers when place in src
//#include "../generic/Qelements.h"
//#include "../generic/hermite_elements.h"
#include "generic.h"
#include "generic/Qelements.h"
#include "generic/hermite_elements.h"
// #include "axisym_solid_traction_elements.cc"
//Needed for the solid mesh
//#include "solid.h"
//#include "../solid/solid_traction_elements.h"
/// Update by Edgar Haener in Feb 2016, use at your own risk. Funny include
/// commands specific to my directory structure due to ignorance of proper use of
/// automake.
namespace oomph
{
//=======================================================================
/// Namespace containing the zero traction function for solid traction
/// elements
//=======================================================================
namespace AxisSolidTractionElementHelper
{
//=======================================================================
/// Default load function (zero traction)
//=======================================================================
void Zero_traction_fct(const Vector<double>& xi,
const Vector<double> &x,
const Vector<double>& N,
Vector<double>& load)
{
unsigned n_dim=load.size();
for (unsigned i=0;i<n_dim;i++) {load[i]=0.0;}
}
}
//======================================================================
/// A class for elements that allow the imposition of an applied traction
/// in the principle of virtual displacements.
/// The geometrical information can be read from the FaceGeometry<ELEMENT>
/// class and and thus, we can be generic enough without the need to have
/// a separate equations class.
//======================================================================
template <class ELEMENT>
class AxisymmetricSolidTractionElement :
public virtual FaceGeometry<ELEMENT>, public virtual FaceElement
//change FaceElement to SolidFaceElement?
{
protected:
/// \short Pointer to an imposed traction function. Arguments:
/// Lagrangian coordinate; Eulerian coordinate; outer unit normal;
/// applied traction. (Not all of the input arguments will be
/// required for all specific load functions but the list should
/// cover all cases)
void (*Traction_fct_pt)(const Vector<double> &xi,
const Vector<double> &x,
const Vector<double> &n,
Vector<double> &result);
/// \short Get the traction vector: Pass number of integration point (dummy),
/// Lagr. coordinate and normal vector and return the load vector
/// (not all of the input arguments will be
/// required for all specific load functions but the list should
/// cover all cases).
void get_traction(const unsigned& intpt,
const Vector<double>& xi,
const Vector<double>& x,
const Vector<double>& n,
Vector<double>& traction)
{
Traction_fct_pt(xi,x,n,traction);
}
/// store the volume under the traction element
double volume;
public:
/// \short Constructor, which takes a "bulk" element and
/// the value of the index and its limit
AxisymmetricSolidTractionElement(FiniteElement* const &element_pt,
const int &face_index) :
FaceGeometry<ELEMENT>(), FaceElement()
{
/// Initialise volume to zero
volume = 0.0;
//std::cout << "Starting constructor" << std::endl;
//Attach the geometrical information to the element. N.B. This function
//also assigns nbulk_value from the required_nvalue of the bulk element
element_pt->build_face_element(face_index,this);
// Zero traction
Traction_fct_pt=&AxisSolidTractionElementHelper::Zero_traction_fct;
}
/// Reference to the traction function pointer
void (* &traction_fct_pt())(const Vector<double>& xi,
const Vector<double>& x,
const Vector<double>& n,
Vector<double>& traction)
{return Traction_fct_pt;}
/// Return the residuals
void fill_in_contribution_to_residuals(Vector<double> &residuals);
/// Return the jacobian
void fill_in_contribution_to_jacobian(Vector<double> &residuals,
DenseMatrix<double> &jacobian)
{
fill_in_contribution_to_residuals(residuals);
//Call the generic FD jacobian calculation
FaceGeometry<ELEMENT>::fill_in_jacobian_from_solid_position_by_fd(jacobian);
//Do I nned to add in derivativs w.r.t. to external data? Not in original...
}
/// Overload the output function
void output(std::ostream &outfile, const unsigned &n_plot)
{FiniteElement::output(outfile,n_plot);}
/// Output function: x,y,[z],u,v,[w],p in tecplot format
void output(std::ostream &outfile) //Changed this
{
unsigned n_plot=5;
FiniteElement::output(outfile,n_plot);
}
/// Overload the output function
void output(FILE* file_pt) {FiniteElement::output(file_pt);}
/// Output function: x,y,[z],u,v,[w],p in tecplot format
void output(FILE* file_pt, const unsigned &n_plot)
{FiniteElement::output(file_pt,n_plot);}
/////////////////////////////////////////////////////////////////////////
//Adding the function that are implemented in SolidFaceElement for solid case
////////////////////////////////////////////////////////////////////////
/// \short The "global" intrinsic coordinate of the element when
/// viewed as part of a geometric object should be given by
/// the FaceElement representation, by default
/// This final over-ride is required because both SolidFiniteElements
/// and FaceElements overload zeta_nodal
double zeta_nodal(const unsigned &n, const unsigned &k,
const unsigned &i) const
{return FaceElement::zeta_nodal(n,k,i);}
/// \short Return i-th FE-interpolated Lagrangian coordinate xi[i] at
/// local coordinate s. Overloaded from SolidFiniteElement. Note that
/// the Lagrangian coordinates are those defined in the bulk!
/// For instance, in a 1D FaceElement that is aligned with
/// the Lagrangian coordinate line xi_0=const, only xi_1 will vary
/// in the FaceElement. This may confuse you if you (wrongly!) believe that
/// in a 1D SolidElement there should only a single Lagrangian
/// coordinate, namely xi_0!
double interpolated_xi(const Vector<double> &s,
const unsigned &i) const
{
// Local coordinates in bulk element
Vector<double> s_bulk(dim()+1);
s_bulk=local_coordinate_in_bulk(s);
// Return Lagrangian coordinate as computed by bulk
return dynamic_cast<SolidFiniteElement*>(bulk_element_pt())->
interpolated_xi(s_bulk,i);
}
/// \short Compute FE interpolated Lagrangian coordinate vector xi[] at
/// local coordinate s as Vector. Overloaded from SolidFiniteElement. Note
/// that the Lagrangian coordinates are those defined in the bulk!
/// For instance, in a 1D FaceElement that is aligned with
/// the Lagrangian coordinate line xi_0=const, only xi_1 will vary
/// in the FaceElement. This may confuse you if you (wrongly!) believe that
/// in a 1D SolidElement there should only a single Lagrangian
/// coordinate, namely xi_0!
void interpolated_xi(const Vector<double> &s,
Vector<double>& xi) const
{
// Local coordinates in bulk element
Vector<double> s_bulk(dim()+1);
s_bulk=local_coordinate_in_bulk(s);
// Get Lagrangian position vector
dynamic_cast<SolidFiniteElement*>(bulk_element_pt())->
interpolated_x(s_bulk,xi);
}
/// Accesse function to the volume
const double get_volume(){
return volume;
}
};
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//=======================================================================
/// Return the residuals for the AxisymmetricSolidTractionElements
//=======================================================================
template<class ELEMENT>
void AxisymmetricSolidTractionElement<ELEMENT>::
fill_in_contribution_to_residuals(Vector<double> &residuals)
{
//Debug flag
bool writeEverythingToFileCSV = false;
// Set volume to zero
volume = 0.0;
//Find out how many nodes there are
unsigned n_node = nnode();
//Find out how many positional dofs there are
//unsigned n_position_type = nnodal_position_type(); //Old version
unsigned n_position_type = this->nnodal_position_type();
//Integer to hold the local equation number
int local_eqn=0;
//Set up memory for the shape functions
//The surface is 1D, so we only have one local derivative
Shape psi(n_node,n_position_type);
DShape dpsids(n_node,n_position_type,1);
//Set the value of n_intpt
unsigned n_intpt = integral_pt()->nweight();
if(writeEverythingToFileCSV){
#include <iostream>
#include <fstream>
std::ofstream csvfile;
csvfile.open ("traction_elements_debug.csv", std::ios::app );
csvfile << "ipt \tx[0] \tx[1] \txi[0] \txi[1] \tdxds[0] \t dxds[1] \tdxids[0] \tdxids[1] \tA11 \tA22 \tw \tW"<< std::endl;
csvfile.close();
}
//Loop over the integration points
for(unsigned ipt=0;ipt<n_intpt;ipt++)
{
//Get the integral weight
double w = integral_pt()->weight(ipt);
//Only need to call the local derivatives
dshape_local_at_knot(ipt,psi,dpsids);
//Calculate the global position and lagrangian coordinate
Vector<double> interpolated_x(2,0.0);
Vector<double> interpolated_xi(2,0.0);
//Calculate the global and lagrangian derivtives wrt the local coordinates
Vector<double> interpolated_dxds(2,0.0);
Vector<double> interpolated_dxids(2,0.0);
//Calculate displacements and derivatives
for(unsigned l=0;l<n_node;l++)
{
//Loop over positional dofs
for(unsigned k=0;k<n_position_type;k++)
{
//Loop over the number of lagrangian coordinates (2)
for(unsigned i=0;i<2;i++)
{
//Calculate the global position
interpolated_x[i] +=
nodal_position_gen(l,bulk_position_type(k),i)*psi(l,k);
interpolated_xi[i] +=
this->lagrangian_position_gen(l,bulk_position_type(k),i)*psi(l,k);
//Calculate the derivatives of the global and lagrangian coordinates
interpolated_dxds[i] +=
nodal_position_gen(l,bulk_position_type(k),i)*dpsids(l,k,0);
interpolated_dxids[i] +=
this->lagrangian_position_gen(l,bulk_position_type(k),i)
*dpsids(l,k,0);
}
}
}
//Now calculate the entries of the deformed surface metric tensor
//Now find the local deformed metric tensor from the tangent Vectors
DenseMatrix<double> A(2);
//The off-diagonal terms are Zero
A(0,1) = A(1,0) = 0.0;
//The diagonal terms are a little complicated
A(0,0) =
(interpolated_dxds[0] - interpolated_x[1]*interpolated_dxids[1])*
(interpolated_dxds[0] - interpolated_x[1]*interpolated_dxids[1]) +
(interpolated_dxds[1] + interpolated_x[0]*interpolated_dxids[1])*
(interpolated_dxds[1] + interpolated_x[0]*interpolated_dxids[1]);
A(1,1) = (interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]))*
(interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]));
//Premultiply the weights and the square-root of the determinant of
//the metric tensor
double W = w*sqrt(A(0,0)*A(1,1));
//Get the outer unit normal
Vector<double> interpolated_normal(2);
//New method of finding outer unit normal is to call function
//outer_unit_normal(ipt,interpolated_normal);
//std::cout << "Modern normel: " << interpolated_normal[0] << ", " << interpolated_normal[1] << std::endl;
//Old way
//Also find the normal -- just the cross product of the metric tensors
//but I want to express it in terms of e_r and e_theta components
//N.B. There is an issue at theta = 0,pi, where the normal is e_{r},
//but given that I never assemble it, should be OK!
//The minus sign is chosen to ensure that the normal is really outward
//Component in the e_{r} direction
interpolated_normal[0] = -1.0*
(interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]))*
(interpolated_dxds[1] + interpolated_x[0]*interpolated_dxids[1]);
//Component in the e_{theta} direction
interpolated_normal[1] = -1.0*
(interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]))*
(interpolated_x[1]*interpolated_dxids[1] - interpolated_dxds[0]);
//TODO: Fix normal direction!
//Huge assumption: we are not going to be on north or south face
//If we're on the north or south face need to flip normal
//if(s_fixed_value()==-1)
//{
// interpolated_normal[0] *= -1.0;
// interpolated_normal[1] *= -1.0;
//}
//Now adjust and scale the normal
double length = 0.0;
for(unsigned i=0;i<2;i++)
{
interpolated_normal[i] *= normal_sign();
length += interpolated_normal[i]*interpolated_normal[i];
}
for(unsigned i=0;i<2;i++)
{
interpolated_normal[i] /= sqrt(length);
}
//std::cout << "Old normel: " << interpolated_normal[0] << ", " << interpolated_normal[1] << std::endl;
//Now calculate the load
Vector<double> traction(2);
get_traction(ipt, interpolated_xi, interpolated_x, interpolated_normal,
traction);
//Normal is outwards
//get_traction(time(),interpolated_x,interpolated_normal,traction); //Original
//=====LOAD TERMS FROM PRINCIPLE OF VIRTUAL DISPLACEMENTS========
Vector<double> cart_pos(2);
// Vector<double> cart_normal(2);
double actual_angle = interpolated_x[1] + interpolated_xi[1] ;
if(writeEverythingToFileCSV){
std::ofstream csvfile;
csvfile.open ("traction_elements_debug.csv", std::ios::app );
csvfile << ipt << " \t" <<interpolated_x[0] << " \t" << interpolated_x[1] << " \t" << interpolated_xi[0] << " \t" << interpolated_xi[1] << " \t" << interpolated_dxds[0] << " \t" << interpolated_dxds[1] << " \t" << interpolated_dxids[0] << " \t" << interpolated_dxids[1] << " \t" << A(0,0) << " \t" << A(1,1) << " \t" << w << " \t" << W << std::endl;
csvfile.close();
}
// volume += W; //to check area, should be 2*pi*r^2
//Get volume from surface integral via divergence theorem
volume += interpolated_x[0]*interpolated_normal[0]*W*-1/3.0;
volume += actual_angle*interpolated_normal[1]*W*-1/3.0;
//Loop over the test functions, nodes of the elemente
for(unsigned l=0;l<n_node;l++)
{
//Loop of types of dofs
for(unsigned k=0;k<n_position_type;k++)
{
//Loop over the displacement components
for(unsigned i=0;i<2;i++)
{
local_eqn =
this->position_local_eqn(l,bulk_position_type(k),i);
/*IF it's not a boundary condition*/
if(local_eqn >= 0)
{
//Add the loading terms to the residuals
residuals[local_eqn] -= traction[i]*psi(l,k)*W;
}
}
} //End of if not boundary condition
} //End of loop over shape functions
} //End of loop over integration points
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//Added by Edgar 12/07/2016
// Forward declaration, otherwise the compiler complains
template <class ELEMENT>
class AxisymmetricSolidTractionVolumeConstraintElement;
//===========AxisSymSolidVolumeConstraint==================================
/// I will try to impose the volume constraint by creating a generalized
/// element that has the equation for the internal pressur p, which is
/// simple the V - V_0 where V_0 is the desired volume. The volume is
/// determined by using the divergence theorem to integrate r . n over
/// the surface. Hence, the volume depends on the traction elements to
/// the inner surface which will need to be added as external data and
/// the pressure for these traction elements is external data for them.
//=========================================================================
template <class ELEMENT>
class AxisSymSolidVolumeConstraintElement : public GeneralisedElement{
protected:
/// Pointer to the desired value of the volume
double *Prescribed_volume_pt;
/// Pointer to mesh of traction elements that will impose the pressure
/// and provide the information about the actual volume
//AxisymmetricSolidTractionVolumeConstraintElement<ELEMENT>* Traction_vol_const_mesh_pt;
SolidMesh* Traction_vol_const_mesh_pt;
// To ensure I only add the external values once.
bool added_external;
/// Volume under mesh
double vol;
public:
/// \short Constructor: pass wanted volume
/// Need to deal with internal/external data?
AxisSymSolidVolumeConstraintElement(double* prescribed_volume_pt){
// Create Data object whose one-and-only value contains the
// unknown pressure to enforce the volume constrain
this->add_internal_data(new Data(1));
//Note to self: access via this->internal_data_pt(0)
added_external = false;
Prescribed_volume_pt = prescribed_volume_pt;
}
///Nothing do delete?
~AxisSymSolidVolumeConstraintElement(){}
// Function to set pointer to surface element mesh and external data
// This cannot be done in the constructor as the traction elements
// have not been created yet.
void set_mesh_pt_and_external(SolidMesh* traction_vol_const_mesh_pt);
// Set to pressure via the difference in volume
void fill_in_contribution_to_residuals(Vector<double> &residuals);
/// Returns target volume
double get_prescribed_volume(){return *Prescribed_volume_pt;}
/// Returns measured volume (last time the residual was run)
double get_current_volume_under_mesh(){return vol;}
};
//======================================================================
/// A class for elements that allow the imposition of an applied traction
/// determined through a volume constraint. Large parts of the code a
/// duplicate from AxisymmetricSolidTractionElement
//======================================================================
template <class ELEMENT>
class AxisymmetricSolidTractionVolumeConstraintElement :
public virtual FaceGeometry<ELEMENT>, public virtual FaceElement
//change FaceElement to SolidFaceElement?
{
protected:
/// Pointer to the AxisSymSolidVolumeConstraintElement that has as internal data the pressure
// Should I used generalised element and dynamic cast?
GeneralisedElement *pressur_control_element_pt;
//Data *pressure_vol_cons_pt;
/// store the volume under the traction element
double volume;
public:
/// \short Constructor, which takes a "bulk" element and
/// the value of the index and its limit
AxisymmetricSolidTractionVolumeConstraintElement(FiniteElement* const &element_pt,
const int &face_index,
GeneralisedElement* const &pressure_pt) :
FaceGeometry<ELEMENT>(), FaceElement()
{
/// Initialise volume to zero
volume = 0.0;
//std::cout << "Starting constructor" << std::endl;
//Attach the geometrical information to the element. N.B. This function
//also assigns nbulk_value from the required_nvalue of the bulk element
element_pt->build_face_element(face_index,this);
// set pointer to pressure
pressur_control_element_pt = pressure_pt;
// add pressure as external data
add_external_data(pressur_control_element_pt->internal_data_pt(0));
}
/// Return the residuals
void fill_in_contribution_to_residuals(Vector<double> &residuals);
/// Return the jacobian
// void fill_in_contribution_to_jacobian(Vector<double> &residuals,
// DenseMatrix<double> &jacobian)
// {
// fill_in_contribution_to_residuals(residuals);
// //Call the generic FD jacobian calculation
// FaceGeometry<ELEMENT>::fill_in_jacobian_from_solid_position_by_fd(jacobian);
//
// //Do I nned to add in derivativs w.r.t. to external data? Not in original...
// }
// Get positions Xr, Xtheta at each integration point
void get_positions(Vector<double> &Xr, Vector<double> &Xtheta)
{
//Find out how many nodes there are
unsigned n_node = nnode();
//Find out how many positional dofs there are
//unsigned n_position_type = nnodal_position_type(); //Old version
unsigned n_position_type = this->nnodal_position_type();
//Set up memory for the shape functions
//The surface is 1D, so we only have one local derivative
Shape psi(n_node,n_position_type);
DShape dpsids(n_node,n_position_type,1);
//Set the value of n_intpt
unsigned n_intpt = integral_pt()->nweight();
//Loop over the integration points
for(unsigned ipt=0;ipt<n_intpt;ipt++)
{
//Only need to call the local derivatives
dshape_local_at_knot(ipt,psi,dpsids);
//Calculate the global position and lagrangian coordinate
Vector<double> interpolated_x(2,0.0);
Vector<double> interpolated_xi(2,0.0);
//Calculate the global and lagrangian derivtives wrt the local coordinates
//Vector<double> interpolated_dxds(2,0.0);
//Vector<double> interpolated_dxids(2,0.0);
//Calculate displacements and derivatives
for(unsigned l=0;l<n_node;l++)
{
//Loop over positional dofs
for(unsigned k=0;k<n_position_type;k++)
{
//Loop over the number of lagrangian coordinates (2)
for(unsigned i=0;i<2;i++)
{
//Calculate the global position
interpolated_x[i] +=
nodal_position_gen(l,bulk_position_type(k),i)*psi(l,k);
interpolated_xi[i] +=
this->lagrangian_position_gen(l,bulk_position_type(k),i)*psi(l,k);
//Calculate the derivatives of the global and lagrangian coordinates
//interpolated_dxds[i] +=
// nodal_position_gen(l,bulk_position_type(k),i)*dpsids(l,k,0);
//interpolated_dxids[i] +=
// this->lagrangian_position_gen(l,bulk_position_type(k),i)
// *dpsids(l,k,0);
}
}
}
if(Xr.size() == n_intpt)
{
Xr[ipt] = interpolated_x[0];
Xtheta[ipt] = interpolated_x[1];
}
else
{
Xr.push_back(interpolated_x[0]);
Xtheta.push_back(interpolated_x[1]);
}
}
}
/// Overload the output function
void output(std::ostream &outfile, const unsigned &n_plot)
{
//FiniteElement::output(outfile,n_plot);
unsigned n_dim = this->nodal_dimension();
//The following does not work - I think I need to overload the
// relevant functions.
//As a stop gap fix I will just output at the integration points
/*
Vector<double> x(n_dim);
Vector<double> xi(n_dim);
Vector<double> s(n_dim-1);
// Tecplot header info
outfile << this->tecplot_zone_string(n_plot);
// Loop over plot points
unsigned num_plot_points=this->nplot_points(n_plot);
for (unsigned iplot=0;iplot<num_plot_points;iplot++)
{
// Get local coordinates of plot point
this->get_s_plot(iplot,n_plot,s);
// Get Eulerian and Lagrangian coordinates and outer unit normal
this->interpolated_x(s,x);
this->interpolated_xi(s,xi);
//Output the Xr,Xtheta,..
//double actual_angel = x[1] + xi[1];
//outfile << x[0] * sin( actual_angel) << " " << x[0] * cos( actual_angel) << " " ;
outfile << x[0]*sin(xi[1]) + x[1]*cos(xi[1]) << " " <<
x[0]*cos(xi[1]) - x[1]*sin(xi[1]) << " ";
for(unsigned i=0;i<n_dim;i++)
{outfile << x[i] << " ";}//1,2
//Output the r,theta,..
for(unsigned i=0;i<n_dim;i++)
{outfile << xi[i] << " ";}//1,2
outfile << s << " ";
outfile << std::endl;
}
*/
// Set volume to zero
volume = 0.0;
//Find out how many nodes there are
unsigned n_node = nnode();
//Find out how many positional dofs there are
//unsigned n_position_type = nnodal_position_type(); //Old version
unsigned n_position_type = this->nnodal_position_type();
//Set up memory for the shape functions
//The surface is 1D, so we only have one local derivative
Shape psi(n_node,n_position_type);
DShape dpsids(n_node,n_position_type,1);
//Set the value of n_intpt
unsigned n_intpt = integral_pt()->nweight();
//Loop over the integration points
for(unsigned ipt=0;ipt<n_intpt;ipt++)
{
//Get the integral weight
double w = integral_pt()->weight(ipt);
//Only need to call the local derivatives
dshape_local_at_knot(ipt,psi,dpsids);
//Calculate the global position and lagrangian coordinate
Vector<double> interpolated_x(2,0.0);
Vector<double> interpolated_xi(2,0.0);
//Calculate the global and lagrangian derivtives wrt the local coordinates
Vector<double> interpolated_dxds(2,0.0);
Vector<double> interpolated_dxids(2,0.0);
//Calculate displacements and derivatives
for(unsigned l=0;l<n_node;l++)
{
//Loop over positional dofs
for(unsigned k=0;k<n_position_type;k++)
{
//Loop over the number of lagrangian coordinates (2)
for(unsigned i=0;i<2;i++)
{
//Calculate the global position
interpolated_x[i] +=
nodal_position_gen(l,bulk_position_type(k),i)*psi(l,k);
interpolated_xi[i] +=
this->lagrangian_position_gen(l,bulk_position_type(k),i)*psi(l,k);
//Calculate the derivatives of the global and lagrangian coordinates
interpolated_dxds[i] +=
nodal_position_gen(l,bulk_position_type(k),i)*dpsids(l,k,0);
interpolated_dxids[i] +=
this->lagrangian_position_gen(l,bulk_position_type(k),i)
*dpsids(l,k,0);
}
}
}
//Now calculate the entries of the deformed surface metric tensor
//Now find the local deformed metric tensor from the tangent Vectors
DenseMatrix<double> A(2);
//The off-diagonal terms are Zero
A(0,1) = A(1,0) = 0.0;
//The diagonal terms are a little complicated
A(0,0) =
(interpolated_dxds[0] - interpolated_x[1]*interpolated_dxids[1])*
(interpolated_dxds[0] - interpolated_x[1]*interpolated_dxids[1]) +
(interpolated_dxds[1] + interpolated_x[0]*interpolated_dxids[1])*
(interpolated_dxds[1] + interpolated_x[0]*interpolated_dxids[1]);
A(1,1) = (interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]))*
(interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]));
//Premultiply the weights and the square-root of the determinant of
//the metric tensor
double W = w*sqrt(A(0,0)*A(1,1));
//Get the outer unit normal
Vector<double> interpolated_normal(2);
//New method of finding outer unit normal is to call function
//outer_unit_normal(ipt,interpolated_normal);
//std::cout << "Modern normel: " << interpolated_normal[0] << ", " << interpolated_normal[1] << std::endl;
//Old way
//Also find the normal -- just the cross product of the metric tensors
//but I want to express it in terms of e_r and e_theta components
//N.B. There is an issue at theta = 0,pi, where the normal is e_{r},
//but given that I never assemble it, should be OK!
//The minus sign is chosen to ensure that the normal is really outward
//Component in the e_{r} direction
interpolated_normal[0] = -1.0*
(interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]))*
(interpolated_dxds[1] + interpolated_x[0]*interpolated_dxids[1]);
//Component in the e_{theta} direction
interpolated_normal[1] = -1.0*
(interpolated_x[0]*sin(interpolated_xi[1]) +
interpolated_x[1]*cos(interpolated_xi[1]))*
(interpolated_x[1]*interpolated_dxids[1] - interpolated_dxds[0]);
//TODO: Fix normal direction!
//Huge assumption: we are not going to be on north or south face
//If we're on the north or south face need to flip normal
//if(s_fixed_value()==-1)
//{
// interpolated_normal[0] *= -1.0;
// interpolated_normal[1] *= -1.0;
//}
//Now adjust and scale the normal
double length = 0.0;
for(unsigned i=0;i<2;i++)
{
interpolated_normal[i] *= normal_sign();
length += interpolated_normal[i]*interpolated_normal[i];
}
for(unsigned i=0;i<2;i++)
{
interpolated_normal[i] /= sqrt(length);
}
//std::cout << "Old normel: " << interpolated_normal[0] << ", " << interpolated_normal[1] << std::endl;
//=====LOAD TERMS FROM PRINCIPLE OF VIRTUAL DISPLACEMENTS========
Vector<double> cart_pos(2);
// Vector<double> cart_normal(2);
//Get volume from surface integral via divergence theorem
// integrating r . n dS
volume += interpolated_x[0]*interpolated_normal[0]*W*-1/3.0;
volume += interpolated_x[1]*interpolated_normal[1]*W*-1/3.0;
outfile << interpolated_x[0]*sin(interpolated_xi[1]) + interpolated_x[1]*cos(interpolated_xi[1]) << " " <<
interpolated_x[0]*cos(interpolated_xi[1]) - interpolated_x[1]*sin(interpolated_xi[1]) << " ";
for(unsigned i=0;i<n_dim;i++)
{outfile << interpolated_x[i] << " ";}//1,2
//Output the r,theta,..
for(unsigned i=0;i<n_dim;i++)
{outfile << interpolated_xi[i] << " ";}//1,2
for(unsigned i=0;i<n_dim;i++)
{outfile << interpolated_normal[i] << " ";}//1,2
outfile << std::endl;
}
}
/// Output function: x,y,[z],u,v,[w],p in tecplot format
void output(std::ostream &outfile) //Changed this
{
unsigned n_plot=5;
output(outfile,n_plot);
}
/// Overload the output function
void output(FILE* file_pt) {FiniteElement::output(file_pt);}
/// Output function: x,y,[z],u,v,[w],p in tecplot format
void output(FILE* file_pt, const unsigned &n_plot)
{
FiniteElement::output(file_pt,n_plot); //Originally just called this
}
/////////////////////////////////////////////////////////////////////////
//Adding the function that are implemented in SolidFaceElement for solid case
////////////////////////////////////////////////////////////////////////
/// \short The "global" intrinsic coordinate of the element when
/// viewed as part of a geometric object should be given by
/// the FaceElement representation, by default
/// This final over-ride is required because both SolidFiniteElements
/// and FaceElements overload zeta_nodal
double zeta_nodal(const unsigned &n, const unsigned &k,
const unsigned &i) const
{return FaceElement::zeta_nodal(n,k,i);}
/// \short Return i-th FE-interpolated Lagrangian coordinate xi[i] at
/// local coordinate s. Overloaded from SolidFiniteElement. Note that
/// the Lagrangian coordinates are those defined in the bulk!
/// For instance, in a 1D FaceElement that is aligned with
/// the Lagrangian coordinate line xi_0=const, only xi_1 will vary
/// in the FaceElement. This may confuse you if you (wrongly!) believe that
/// in a 1D SolidElement there should only a single Lagrangian
/// coordinate, namely xi_0!
double interpolated_xi(const Vector<double> &s,
const unsigned &i) const
{
// Local coordinates in bulk element
Vector<double> s_bulk(dim()+1);
s_bulk=local_coordinate_in_bulk(s);
// Return Lagrangian coordinate as computed by bulk
return dynamic_cast<SolidFiniteElement*>(bulk_element_pt())->
interpolated_xi(s_bulk,i);
}
/// \short Compute FE interpolated Lagrangian coordinate vector xi[] at
/// local coordinate s as Vector. Overloaded from SolidFiniteElement. Note
/// that the Lagrangian coordinates are those defined in the bulk!
/// For instance, in a 1D FaceElement that is aligned with
/// the Lagrangian coordinate line xi_0=const, only xi_1 will vary
/// in the FaceElement. This may confuse you if you (wrongly!) believe that
/// in a 1D SolidElement there should only a single Lagrangian
/// coordinate, namely xi_0!
void interpolated_xi(const Vector<double> &s,
Vector<double>& xi) const
{
// Local coordinates in bulk element
Vector<double> s_bulk(dim()+1);
s_bulk=local_coordinate_in_bulk(s);
// Get Lagrangian position vector
dynamic_cast<SolidFiniteElement*>(bulk_element_pt())->
interpolated_x(s_bulk,xi);
}
/// Accesse function to the volume
const double get_volume(){
return volume;
}
};
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//=======================================================================
/// Return the residuals for the AxisymmetricSolidTractionVolumeConstraints
//=======================================================================
template<class ELEMENT>
void AxisymmetricSolidTractionVolumeConstraintElement<ELEMENT>::
fill_in_contribution_to_residuals(Vector<double> &residuals)
{
//Debug flag
bool writeEverythingToFileCSV = false;
// Set volume to zero
volume = 0.0;
//Find out how many nodes there are
unsigned n_node = nnode();
//Find out how many positional dofs there are
//unsigned n_position_type = nnodal_position_type(); //Old version
unsigned n_position_type = this->nnodal_position_type();
//Integer to hold the local equation number
int local_eqn=0;
//Set up memory for the shape functions
//The surface is 1D, so we only have one local derivative
Shape psi(n_node,n_position_type);
DShape dpsids(n_node,n_position_type,1);