elements.cc
Go to the documentation of this file.
1// LIC// ====================================================================
2// LIC// This file forms part of oomph-lib, the object-oriented,
3// LIC// multi-physics finite-element library, available
4// LIC// at http://www.oomph-lib.org.
5// LIC//
6// LIC// Copyright (C) 2006-2026 Matthias Heil and Andrew Hazel
7// LIC//
8// LIC// This library is free software; you can redistribute it and/or
9// LIC// modify it under the terms of the GNU Lesser General Public
10// LIC// License as published by the Free Software Foundation; either
11// LIC// version 2.1 of the License, or (at your option) any later version.
12// LIC//
13// LIC// This library is distributed in the hope that it will be useful,
14// LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// LIC// Lesser General Public License for more details.
17// LIC//
18// LIC// You should have received a copy of the GNU Lesser General Public
19// LIC// License along with this library; if not, write to the Free Software
20// LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21// LIC// 02110-1301 USA.
22// LIC//
23// LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24// LIC//
25// LIC//====================================================================
26// Non-inline member functions for generic elements
27
28#include <float.h>
29
30// oomph-lib includes
31#include "elements.h"
32#include "timesteppers.h"
33#include "integral.h"
34#include "shape.h"
35#include "oomph_definitions.h"
37
38namespace oomph
39{
40 /// Static boolean to suppress warnings about any repeated
41 /// data. Defaults to false.
43
44
45 /// Static boolean to suppress warnings about repeated internal
46 /// data. Defaults to false
48 false;
49
50
51 /// Static boolean to suppress warnings about repeated external
52 /// data. Defaults to true
54
55
56 ///////////////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////////////
58 // Functions for generalised elements
59 ///////////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////////
61
62 //=======================================================================
63 /// Add a (pointer to an) internal data object to the element and
64 /// return the index required to obtain it from the access
65 /// function \c internal_data_pt()
66 //=======================================================================
68 const bool& fd)
69 {
70 // Local cache of numbers of internal and external data
71 const unsigned n_internal_data = Ninternal_data;
72 const unsigned n_external_data = Nexternal_data;
73
74 // Find out whether the data is already stored in the array
75
76 // Loop over the number of internals
77 // The internal data are stored at the beginning of the array
78 for (unsigned i = 0; i < n_internal_data; i++)
79 {
80 // If the passed pointer is stored in the array
82 {
83#ifdef PARANOID
85 {
86 oomph_info << std::endl << std::endl;
88 << "---------------------------------------------------------------"
89 "--"
90 << std::endl
91 << "Info: Data is already included in this element's internal "
92 "storage."
93 << std::endl
94 << "It's stored as entry " << i << " and I'm not adding it again."
95 << std::endl
96 << std::endl
97 << "Note: You can suppress this message by recompiling without"
98 << "\n PARANOID or setting the boolean \n"
99 << "\n "
100 "GeneralisedElement::Suppress_warning_about_repeated_internal_"
101 "data"
102 << "\n\n to true." << std::endl
103 << "---------------------------------------------------------------"
104 "--"
105 << std::endl
106 << std::endl;
107 }
108#endif
109 // Return the index to the data object
110 return i;
111 }
112 }
113
114 // Allocate new storage for the pointers to data
116
117 // Copy the old internal values across to the beginning of the array
118 for (unsigned i = 0; i < n_internal_data; i++)
119 {
121 }
122
123 // Now add the new value to the end of the internal data
125
126 // Copy the external values across
127 for (unsigned i = 0; i < n_external_data; i++)
128 {
130 }
131
132 // Delete the storage associated with the previous values
133 delete[] Data_pt;
134
135 // Set the pointer to the new storage
137
138 // Resize the array of boolean flags
140 // Shuffle the flags for the external data to the end of the array
141 for (unsigned i = n_external_data; i > 0; i--)
142 {
144 }
145 // Now add the new flag to the end of the internal data
147
148 // Increase the number of internals
150
151 // Return the final index to the new internal data
152 return n_internal_data;
153 }
154
155 //=======================================================================
156 /// Add the contents of the queue global_eqn_numbers to
157 /// the local storage for the equation numbers, which represents the
158 /// local-to-global translation scheme. It is essential that the entries
159 /// are added in order, i.e. from the front.
160 //=======================================================================
162 std::deque<unsigned long> const& global_eqn_numbers,
163 std::deque<double*> const& global_dof_pt)
164 {
165 // Find the number of dofs
166 const unsigned n_dof = Ndof;
167 // Find the number of additional dofs
168 const unsigned n_additional_dof = global_eqn_numbers.size();
169 // If there are none, return immediately
170 if (n_additional_dof == 0)
171 {
172 return;
173 }
174
175 // Find the new total number of equation numbers
176 const unsigned new_n_dof = n_dof + n_additional_dof;
177 // Create storage for all equations, initialised to NULL
178 unsigned long* new_eqn_number = new unsigned long[new_n_dof];
179
180 // Copy over the existing values to the start new storage
181 for (unsigned i = 0; i < n_dof; i++)
182 {
184 }
185
186 // Set an index to the next position in the new storage
187 unsigned index = n_dof;
188 // Loop over the queue and add it's entries to our new storage
189 for (std::deque<unsigned long>::const_iterator it =
190 global_eqn_numbers.begin();
191 it != global_eqn_numbers.end();
192 ++it)
193 {
194 // Add the value to the storage
195 new_eqn_number[index] = *it;
196 // Increase the array index
197 ++index;
198 }
199
200
201 // If a non-empty dof deque has been passed then do stuff
202 const unsigned n_additional_dof_pt = global_dof_pt.size();
203 if (n_additional_dof_pt > 0)
204 {
205// If it's size is not the same as the equation numbers complain
206#ifdef PARANOID
208 {
209 std::ostringstream error_stream;
211 << "global_dof_pt is non-empty, yet it does not have the same size\n"
212 << "as global_eqn_numbers.\n"
213 << "There are " << n_additional_dof << " equation numbers,\n"
214 << "but " << n_additional_dof_pt << std::endl;
215
216 throw OomphLibError(
218 }
219#endif
220
221 // Create storge for all dofs initialised to NULL
222 double** new_dof_pt = new double*[new_n_dof];
223 // Copy over the exisiting values to the start of new storage
224 for (unsigned i = 0; i < n_dof; i++)
225 {
226 new_dof_pt[i] = Dof_pt[i];
227 }
228
229 // Set an index to the next position in the new storage
230 unsigned index = n_dof;
231 // Loop over the queue and add it's entries to our new storage
232 for (std::deque<double*>::const_iterator it = global_dof_pt.begin();
233 it != global_dof_pt.end();
234 ++it)
235 {
236 // Add the value to the storage
237 new_dof_pt[index] = *it;
238 // Increase the array index
239 ++index;
240 }
241
242 // Now delete the old storage
243 delete[] Dof_pt;
244 // Set the pointer to address the new storage
246 }
247
248 // Now delete the old for the equation numbers storage
249 delete[] Eqn_number;
250 // Set the pointer to address the new storage
252 // Finally update the number of degrees of freedom
253 Ndof = new_n_dof;
254 }
255
256 //========================================================================
257 /// Empty dense matrix used as a dummy argument to combined
258 /// residual and jacobian functions in the case when only the residuals
259 /// are being assembled
260 //========================================================================
262
263 //========================================================================
264 /// Static storage used when pointers to the dofs are being assembled by
265 /// add_global_eqn_numbers()
266 //========================================================================
267 std::deque<double*> GeneralisedElement::Dof_pt_deque;
268
269
270 //=========================================================================
271 /// Default value used as the increment for finite difference calculations
272 /// of the jacobian matrices
273 //=========================================================================
275
276 //==========================================================================
277 /// Destructor for generalised elements: Wipe internal data. Pointers
278 /// to external data get NULLed but are not deleted because they
279 /// are (generally) shared by lots of elements.
280 //==========================================================================
282 {
283 // Delete each of the objects stored as internal data
284 for (unsigned i = Ninternal_data; i > 0; i--)
285 {
286 // The objects are stored at the beginning of the Data_pt array
287 delete Data_pt[i - 1];
288 Data_pt[i - 1] = 0;
289 }
290
291 // Now delete the storage for internal and external data
292 delete[] Data_pt;
293
294 // Now if we have allocated storage for the local equation for
295 // the internal and external data, delete it.
296 if (Data_local_eqn)
297 {
298 delete[] Data_local_eqn[0];
299 delete[] Data_local_eqn;
300 }
301
302 // Delete the storage for the global equation numbers
303 delete[] Eqn_number;
304 }
305
306
307 //=======================================================================
308 /// Add a (pointer to an) external data object to the element and
309 /// return the index required to obtain it from the access
310 /// function \c external_data_pt()
311 //=======================================================================
313 const bool& fd)
314 {
315 // Find the numbers of internal and external data
316 const unsigned n_internal_data = Ninternal_data;
317 const unsigned n_external_data = Nexternal_data;
318 // Find out whether the data is already stored in the array
319
320 // Loop over the number of externals
321 // The external data are stored at the end of the array Data_pt
322 for (unsigned i = 0; i < n_external_data; i++)
323 {
324 // If the passed pointer is stored in the array
325 if (external_data_pt(i) == data_pt)
326 {
327#ifdef PARANOID
329 {
330 oomph_info << std::endl << std::endl;
332 << "---------------------------------------------------------------"
333 "--"
334 << std::endl
335 << "Info: Data is already included in this element's external "
336 "storage."
337 << std::endl
338 << "It's stored as entry " << i << " and I'm not adding it again"
339 << std::endl
340 << std::endl
341 << "Note: You can suppress this message by recompiling without"
342 << "\n PARANOID or setting the boolean \n"
343 << "\n "
344 "GeneralisedElement::Suppress_warning_about_repeated_external_"
345 "data"
346 << "\n\n to true." << std::endl
347 << "---------------------------------------------------------------"
348 "--"
349 << std::endl
350 << std::endl;
351 }
352#endif
353 // Return the index to the data object
354 return i;
355 }
356 }
357
358 // Allocate new storage for the pointers to data
360
361 // Copy the old internal and external values across to the new array
362 for (unsigned i = 0; i < (n_internal_data + n_external_data); i++)
363 {
365 }
366
367 // Add the new data pointer to the end of the array
369
370 // Delete the storage associated with the previous values
371 delete[] Data_pt;
372
373 // Set the pointer to the new storage
375
376 // Resize the array of boolean flags
378 // Now add the new flag to the end of the external data
380
381 // Increase the number of externals
383
384 // Return the final index to the new external data
385 return n_external_data;
386 }
387
388 //========================================================================
389 /// Flush all the external data, i.e. clear the pointers to external
390 /// data from the internal storage.
391 //========================================================================
393 {
394 // Get the numbers of internal and external data
395 const unsigned n_external_data = Nexternal_data;
396 // If there is external data
397 if (n_external_data > 0)
398 {
399 // Storage for new data, initialised to NULL
400 Data** new_data_pt = 0;
401
402 // Find the number of internal data
403 const unsigned n_internal_data = Ninternal_data;
404 // If there is internal data resize Data_pt and copy over
405 // the pointers
406 if (n_internal_data > 0)
407 {
408 // The new data pointer should only be the size of the internal data
410 // Copy over the internal data only
411 for (unsigned i = 0; i < n_internal_data; i++)
412 {
414 }
415 }
416
417 // Delete the old storage
418 delete[] Data_pt;
419 // Set the new storage, this will be NULL if there is no internal data
421 // Set the number of externals to zero
422 Nexternal_data = 0;
423
424 // Resize the array of boolean flags to the number of internals
425 Data_fd.resize(n_internal_data);
426 }
427 }
428
429
430 //=========================================================================
431 /// Remove the object addressed by data_pt from the external data array
432 /// Note that this could mess up the numbering of other external data
433 //========================================================================
435 {
436 // Get the current numbers of external data
437 const unsigned n_external_data = Nexternal_data;
438 // Index of the data to be removed
439 // We initialise this to be n_external_data, and it will be smaller than
440 // n_external_data if the data pointer is found in the array
441 unsigned index = n_external_data;
442 // Loop over the external data and find the argument
443 for (unsigned i = 0; i < n_external_data; i++)
444 {
445 // If we have found the data pointer, set the index and break
446 if (external_data_pt(i) == data_pt)
447 {
448 index = i;
449 break;
450 }
451 }
452
453 // If we have found an index less than Nexternal_data, then we have found
454 // the data in the array
455 if (index < n_external_data)
456 {
457 // Initialise a new array to NULL
458 Data** new_data_pt = 0;
459
460 // Find the number of internals
461 const unsigned n_internal_data = Ninternal_data;
462
463 // Find the new number of total data items (one fewer)
464 const unsigned n_total_data = n_internal_data + n_external_data - 1;
465
466 // Create a new array containing the data items, if we have any
467 if (n_total_data > 0)
468 {
470 }
471
472 // Copy over all the internal data
473 for (unsigned i = 0; i < n_internal_data; i++)
474 {
476 }
477
478 // Now copy over the un-flushed data
479 unsigned counter = 0;
480 for (unsigned i = 0; i < n_external_data; i++)
481 {
482 // If we are not at the deleted index
483 if (i != index)
484 {
485 // Copy the undeleted entry into the next entry in our new
486 // array of pointers to Data
488 // Increase the counter
489 ++counter;
490 }
491 }
492
493 // Delete the storage associated with the previous values
494 delete[] Data_pt;
495
496 // Set pointers to the new storage, will be NULL if no data left
498
499 // Remove the entry from the array of boolean flags
500 Data_fd.erase(Data_fd.begin() + n_internal_data + index);
501
502 // Decrease the number of externals
504
505 // Issue a warning if there will be external data remaining
506 if (Nexternal_data > 1)
507 {
508 std::ostringstream warning_stream;
510 << "Data removed from element's external data " << std::endl
511 << "You may have to update the indices for remaining data "
512 << std::endl
513 << "This can be achieved by using add_external_data() "
514 << std::endl;
516 "GeneralisedElement::flush_external_data()",
518 }
519 }
520 }
521
522
523 //==========================================================================
524 /// This function loops over the internal data of the element and assigns
525 /// GLOBAL equation numbers to the data objects.
526 ///
527 /// Pass the current total number of dofs, global_number, which gets
528 /// incremented, and Dof_pt, the Vector of pointers to the global dofs
529 /// (to which any internal dofs are added).
530 //==========================================================================
532 unsigned long& global_number, Vector<double*>& Dof_pt)
533 {
534 // Loop over the internal data and assign the equation numbers
535 // The internal data are stored at the beginning of the Data_pt array
536 for (unsigned i = 0; i < Ninternal_data; i++)
537 {
539 }
540 }
541
542
543 //==========================================================================
544 /// Function to describe the dofs of the Element. The ostream
545 /// specifies the output stream to which the description
546 /// is written; the string stores the currently
547 /// assembled output that is ultimately written to the
548 /// output stream by Data::describe_dofs(...); it is typically
549 /// built up incrementally as we descend through the
550 /// call hierarchy of this function when called from
551 /// Problem::describe_dofs(...)
552 //==========================================================================
554 std::ostream& out, const std::string& current_string) const
555 {
556 for (unsigned i = 0; i < Ninternal_data; i++)
557 {
558 std::stringstream conversion;
559 conversion << " of Internal Data " << i << current_string;
560 std::string in(conversion.str());
562 }
563 }
564
565 //==========================================================================
566 /// Function to describe the local dofs of the element. The ostream
567 /// specifies the output stream to which the description
568 /// is written; the string stores the currently
569 /// assembled output that is ultimately written to the
570 /// output stream by Data::describe_dofs(...); it is typically
571 /// built up incrementally as we descend through the
572 /// call hierarchy of this function when called from
573 /// Problem::describe_dofs(...)
574 //==========================================================================
576 std::ostream& out, const std::string& current_string) const
577 {
578 // Find the number of internal and external data
579 const unsigned n_internal_data = Ninternal_data;
580 const unsigned n_external_data = Nexternal_data;
581
582 // Now loop over the internal data and describe local equation numbers
583 for (unsigned i = 0; i < n_internal_data; i++)
584 {
585 // Pointer to the internal data
586 Data* const data_pt = internal_data_pt(i);
587
588 std::stringstream conversion;
589 conversion << " of Internal Data " << i << current_string;
590 std::string in(conversion.str());
592 }
593
594
595 // Now loop over the external data and assign local equation numbers
596 for (unsigned i = 0; i < n_external_data; i++)
597 {
598 // Pointer to the external data
599 Data* const data_pt = external_data_pt(i);
600
601 std::stringstream conversion;
602 conversion << " of External Data " << i << current_string;
603 std::string in(conversion.str());
605 }
606 }
607
608 //==========================================================================
609 /// This function loops over the internal data of the element and add
610 /// pointers to their unconstrained values to a map indexed by the global
611 /// equation number.
612 //==========================================================================
614 std::map<unsigned, double*>& map_of_value_pt)
615 {
616 // Loop over the internal data and add their data to the map
617 // The internal data are stored at the beginning of the Data_pt array
618 for (unsigned i = 0; i < Ninternal_data; i++)
619 {
621 }
622 }
623
624
625#ifdef OOMPH_HAS_MPI
626 //=========================================================================
627 /// Add all internal data and time history values to the vector in
628 /// the internal storage order
629 //=========================================================================
638
639 //========================================================================
640 /// Read all internal data and time history values from the vector
641 /// starting from index. On return the index will be
642 /// set to the value at the end of the data that has been read in
643 //========================================================================
645 const Vector<double>& vector_of_values, unsigned& index)
646 {
647 for (unsigned i = 0; i < Ninternal_data; i++)
648 {
650 }
651 }
652
653 //=========================================================================
654 /// Add all equation numbers associated with internal data
655 /// to the vector in the internal storage order
656 //=========================================================================
665
666 //=========================================================================
667 /// Read all equation numbers associated with internal data
668 /// from the vector
669 /// starting from index. On return the index will be
670 /// set to the value at the end of the data that has been read in
671 //=========================================================================
673 const Vector<long>& vector_of_eqn_numbers, unsigned& index)
674 {
675 for (unsigned i = 0; i < Ninternal_data; i++)
676 {
678 index);
679 }
680 }
681
682#endif
683
684
685 //====================================================================
686 /// Setup the arrays of local equation numbers for the element.
687 /// In general, this function should not need to be overloaded. Instead
688 /// the function assign_all_generic_local_eqn_numbers() will be overloaded
689 /// by different types of Element.
690 /// That said, the function is virtual so that it
691 /// may be overloaded by the user if they *really* know what they are doing.
692 //==========================================================================
694 const bool& store_local_dof_pt)
695 {
699
700 // Check that no global equation numbers are repeated
701#ifdef PARANOID
702
703 std::ostringstream error_stream;
704
705 // Loop over the array of equation numbers and add to set to assess
706 // uniqueness
707 std::map<unsigned, bool> is_repeated;
708 std::set<unsigned long> set_of_global_eqn_numbers;
709 unsigned old_ndof = 0;
710 for (unsigned n = 0; n < Ndof; ++n)
711 {
714 {
715 error_stream << "Repeated global eqn: " << Eqn_number[n] << std::endl;
716 is_repeated[Eqn_number[n]] = true;
717 }
719 }
720
721 // If the sizes do not match we have a repeat, throw an error
723 {
724#ifdef OOMPH_HAS_MPI
725 error_stream << "Element is ";
726 if (!is_halo()) error_stream << "not ";
727 error_stream << "a halo element\n\n";
728#endif
729 error_stream << "\nLocal/lobal equation numbers: " << std::endl;
730 for (unsigned n = 0; n < Ndof; ++n)
731 {
732 error_stream << " " << n << " " << Eqn_number[n] << std::endl;
733 }
734
735 // It's helpful for debugging purposes to output more about this element
736 error_stream << std::endl << " element address is " << this << std::endl;
737
738 // Check if the repeated dofs are among the internal Data values
739 unsigned nint = this->ninternal_data();
740 error_stream << "Number of internal data " << nint << std::endl;
741 for (unsigned i = 0; i < nint; i++)
742 {
743 Data* data_pt = this->internal_data_pt(i);
744 unsigned nval = data_pt->nvalue();
745 for (unsigned j = 0; j < nval; j++)
746 {
747 int eqn_no = data_pt->eqn_number(j);
748 error_stream << "Internal dof: " << eqn_no << std::endl;
749 if (is_repeated[unsigned(eqn_no)])
750 {
751 error_stream << "Repeated internal dof: " << eqn_no << std::endl;
752 }
753 }
754 }
755
756 // Check if the repeated dofs are among the external Data values
757 unsigned next = this->nexternal_data();
758 error_stream << "Number of external data " << next << std::endl;
759 for (unsigned i = 0; i < next; i++)
760 {
761 Data* data_pt = this->external_data_pt(i);
762 unsigned nval = data_pt->nvalue();
763 for (unsigned j = 0; j < nval; j++)
764 {
765 int eqn_no = data_pt->eqn_number(j);
766 error_stream << "External dof: " << eqn_no << std::endl;
767 if (is_repeated[unsigned(eqn_no)])
768 {
769 error_stream << "Repeated external dof: " << eqn_no;
770 Node* nod_pt = dynamic_cast<Node*>(data_pt);
771 if (nod_pt != 0)
772 {
773 error_stream << " (is a node at: ";
774 unsigned ndim = nod_pt->ndim();
775 for (unsigned ii = 0; ii < ndim; ii++)
776 {
777 error_stream << nod_pt->x(ii) << " ";
778 }
779 }
780 error_stream << ")\n";
781 }
782 }
783 }
784
785
786 // If it's an element with external element check the associated
787 // Data
789 dynamic_cast<ElementWithExternalElement*>(this);
790 if (e_el_pt != 0)
791 {
792 // Check if the repeated dofs are among the external Data values
793 {
794 unsigned next = e_el_pt->nexternal_interaction_field_data();
795 error_stream << "Number of external element data " << next
796 << std::endl;
797 Vector<Data*> data_pt(e_el_pt->external_interaction_field_data_pt());
798 for (unsigned i = 0; i < next; i++)
799 {
800 unsigned nval = data_pt[i]->nvalue();
801 for (unsigned j = 0; j < nval; j++)
802 {
803 int eqn_no = data_pt[i]->eqn_number(j);
804 error_stream << "External element dof: " << eqn_no << std::endl;
805 if (is_repeated[unsigned(eqn_no)])
806 {
807 error_stream << "Repeated external element dof: " << eqn_no;
808 Node* nod_pt = dynamic_cast<Node*>(data_pt[i]);
809 if (nod_pt != 0)
810 {
811 error_stream << " (is a node at: ";
812 unsigned ndim = nod_pt->ndim();
813 for (unsigned ii = 0; ii < ndim; ii++)
814 {
815 error_stream << nod_pt->x(ii) << " ";
816 }
817 }
818 error_stream << ")\n";
819 }
820 }
821 }
822 }
823
824
825 // Check if the repeated dofs are among the external geom Data values
826 {
827 unsigned next = e_el_pt->nexternal_interaction_geometric_data();
828 error_stream << "Number of external element geom data " << next
829 << std::endl;
831 e_el_pt->external_interaction_geometric_data_pt());
832 for (unsigned i = 0; i < next; i++)
833 {
834 unsigned nval = data_pt[i]->nvalue();
835 for (unsigned j = 0; j < nval; j++)
836 {
837 int eqn_no = data_pt[i]->eqn_number(j);
838 error_stream << "External element geometric dof: " << eqn_no
839 << std::endl;
840 if (is_repeated[unsigned(eqn_no)])
841 {
843 << "Repeated external element geometric dof: " << eqn_no
844 << " " << data_pt[i]->value(j);
845 Node* nod_pt = dynamic_cast<Node*>(data_pt[i]);
846 if (nod_pt != 0)
847 {
848 error_stream << " (is a node at: ";
849 unsigned ndim = nod_pt->ndim();
850 for (unsigned ii = 0; ii < ndim; ii++)
851 {
852 error_stream << nod_pt->x(i) << " ";
853 }
854 error_stream << ")";
855 }
856 error_stream << "\n";
857 }
858 }
859 }
860 }
861 }
862
863 // If it's a FiniteElement then output its nodes
864 FiniteElement* f_el_pt = dynamic_cast<FiniteElement*>(this);
865 if (f_el_pt != 0)
866 {
867 unsigned n_node = f_el_pt->nnode();
868 for (unsigned n = 0; n < n_node; n++)
869 {
871 unsigned nval = nod_pt->nvalue();
872 for (unsigned j = 0; j < nval; j++)
873 {
874 int eqn_no = nod_pt->eqn_number(j);
875 error_stream << "Node " << n << ": Nodal dof: " << eqn_no;
876 if (eqn_no >= 0)
877 {
878 if (is_repeated[unsigned(eqn_no)])
879 {
880 error_stream << "Node " << n
881 << ": Repeated nodal dof: " << eqn_no;
882 if (j >= f_el_pt->required_nvalue(n))
883 {
884 error_stream << " (resized)";
885 }
886 error_stream << std::endl;
887 }
888 }
889 }
890 SolidNode* solid_nod_pt = dynamic_cast<SolidNode*>(nod_pt);
891 if (solid_nod_pt != 0)
892 {
893 Data* data_pt = solid_nod_pt->variable_position_pt();
894 unsigned nval = data_pt->nvalue();
895 for (unsigned j = 0; j < nval; j++)
896 {
897 int eqn_no = data_pt->eqn_number(j);
898 error_stream << "Node " << n << ": Positional dof: " << eqn_no
899 << std::endl;
900 if (is_repeated[unsigned(eqn_no)])
901 {
902 error_stream << "Repeated positional dof: " << eqn_no << " "
903 << data_pt->value(j) << std::endl;
904 }
905 }
906 }
907 }
908
909 // Output nodal coordinates of element
910 n_node = f_el_pt->nnode();
911 for (unsigned n = 0; n < n_node; n++)
912 {
914 unsigned n_dim = nod_pt->ndim();
915 error_stream << "Node " << n << " at ( ";
916 for (unsigned i = 0; i < n_dim; i++)
917 {
918 error_stream << nod_pt->x(i) << " ";
919 }
920 error_stream << ")" << std::endl;
921 }
922 }
923
924
925 // Shout?
927 {
928 error_stream << std::endl << std::endl;
930 << "---------------------------------------------------------------"
931 "--"
932 << std::endl
933 << "Note: You can suppress this warning by recompiling without"
934 << "\n PARANOID or setting the boolean \n"
935 << "\n "
936 "GeneralisedElement::Suppress_warning_about_any_repeated_data"
937 << "\n\n to true." << std::endl
938 << std::endl
939 << "Only do this if you know what you're doing; repeated equation\n"
940 << "numbers are usually a sign of trouble...\n"
941 << "---------------------------------------------------------------"
942 "--"
943 << std::endl
944 << std::endl;
945
946 // Issue warning
949 }
950 }
951#endif
952 }
953
954
955 //==========================================================================
956 /// This function loops over the internal and external data of the element,
957 /// adds the GLOBAL equation numbers to the local-to-global look-up scheme and
958 /// fills in the look-up schemes for the local equation
959 /// numbers.
960 /// If the boolean argument is true then pointers to the dofs will be
961 /// stored in Dof_pt
962 //==========================================================================
964 const bool& store_local_dof_pt)
965 {
966 // Find the number of internal and external data
967 const unsigned n_internal_data = Ninternal_data;
968 const unsigned n_external_data = Nexternal_data;
969 // Find the total number of data
971
972 // If there is data
973 if (n_total_data > 0)
974 {
975 // Find the number of local equations assigned so far
976 unsigned local_eqn_number = ndof();
977
978 // We need to find the total number of values stored in all the
979 // internal and external data
980 // Initialise to the number stored in the first data object
981 unsigned n_total_values = Data_pt[0]->nvalue();
982 // Loop over the other data and add the number of values stored
983 for (unsigned i = 1; i < n_total_data; ++i)
984 {
986 }
987
988 // If allocated delete the old storage
989 if (Data_local_eqn)
990 {
991 delete[] Data_local_eqn[0];
992 delete[] Data_local_eqn;
993 }
994
995 // If there are no values then we are done, null out the storage and
996 // return
997 if (n_total_values == 0)
998 {
999 Data_local_eqn = 0;
1000 return;
1001 }
1002
1003 // Allocate the storage for the local equation numbers
1004 // The idea is that we store internal equation numbers followed by
1005 // external equation numbers
1006
1007 // Firstly allocate pointers to the rows for each data item
1008 Data_local_eqn = new int*[n_total_data];
1009 // Now allocate storage for all the equation numbers
1010 Data_local_eqn[0] = new int[n_total_values];
1011 // Set all values to be unclassified
1012 for (unsigned i = 0; i < n_total_values; ++i)
1013 {
1015 }
1016
1017 // Loop over the remaining rows and set their pointers
1018 for (unsigned i = 1; i < n_total_data; ++i)
1019 {
1020 // Initially set the pointer to the i-th row to the pointer
1021 // to the i-1th row
1023 // Now increase the row pointer by the number of values
1024 // stored at the i-1th data object
1025 Data_local_eqn[i] += Data_pt[i - 1]->nvalue();
1026 }
1027
1028 // A local queue to store the global equation numbers
1029 std::deque<unsigned long> global_eqn_number_queue;
1030
1031 // Now loop over the internal data and assign local equation numbers
1032 for (unsigned i = 0; i < n_internal_data; i++)
1033 {
1034 // Pointer to the internal data
1035 Data* const data_pt = internal_data_pt(i);
1036 // Find the number of values stored at the internal data
1037 unsigned n_value = data_pt->nvalue();
1038
1039 // Loop over the number of values
1040 for (unsigned j = 0; j < n_value; j++)
1041 {
1042 // Get the GLOBAL equation number
1043 long eqn_number = data_pt->eqn_number(j);
1044 // If the GLOBAL equation number is positive (a free variable)
1045 if (eqn_number >= 0)
1046 {
1047 // Add the GLOBAL equation number to the queue
1049 // Add pointer to the dof to the queue if required
1051 {
1052 GeneralisedElement::Dof_pt_deque.push_back(data_pt->value_pt(j));
1053 }
1054 // Add the local equation number to the storage scheme
1056 // Increase the local number
1058 }
1059 else
1060 {
1061 // Set the local scheme to be pinned
1063 }
1064 }
1065 } // End of loop over internal data
1066
1067
1068 // Now loop over the external data and assign local equation numbers
1069 for (unsigned i = 0; i < n_external_data; i++)
1070 {
1071 // Pointer to the external data
1072 Data* const data_pt = external_data_pt(i);
1073 // Find the number of values stored at the external data
1074 unsigned n_value = data_pt->nvalue();
1075
1076 // Loop over the number of values
1077 for (unsigned j = 0; j < n_value; j++)
1078 {
1079 // Get the GLOBAL equation number
1080 long eqn_number = data_pt->eqn_number(j);
1081 // If the GLOBAL equation number is positive (a free variable)
1082 if (eqn_number >= 0)
1083 {
1084 // Add the GLOBAL equation number to the queue
1086 // Add pointer to the dof to the queue if required
1088 {
1089 GeneralisedElement::Dof_pt_deque.push_back(data_pt->value_pt(j));
1090 }
1091 // Add the local equation number to the local scheme
1093 // Increase the local number
1095 }
1096 else
1097 {
1098 // Set the local scheme to be pinned
1100 }
1101 }
1102 }
1103
1104 // Now add our global equations numbers to the internal element storage
1107 // Clear the memory used in the deque
1109 {
1110 std::deque<double*>().swap(GeneralisedElement::Dof_pt_deque);
1111 }
1112 }
1113 }
1114
1115
1116 //============================================================================
1117 /// This function calculates the entries of Jacobian matrix, used in
1118 /// the Newton method, associated with the internal degrees of freedom.
1119 /// It does this using finite differences,
1120 /// rather than an analytical formulation, so can be done in total generality.
1121 /// If the boolean argument is true, the finite
1122 /// differencing will be performed for all internal data, irrespective of
1123 /// the information in Data_fd. The default value (false)
1124 /// uses the information in Data_fd to selectively difference only
1125 /// certain data.
1126 //==========================================================================
1129 DenseMatrix<double>& jacobian,
1130 const bool& fd_all_data)
1131 {
1132 // Locally cache the number of internal data
1133 const unsigned n_internal_data = Ninternal_data;
1134
1135 // If there aren't any internal data, then return straight away
1136 if (n_internal_data == 0)
1137 {
1138 return;
1139 }
1140
1141 // Call the update function to ensure that the element is in
1142 // a consistent state before finite differencing starts
1144
1145 // Find the number of dofs in the element
1146 const unsigned n_dof = ndof();
1147
1148 // Create newres vector
1150
1151 // Integer storage for local unknown
1152 int local_unknown = 0;
1153
1154 // Use the default finite difference step
1155 const double fd_step = Default_fd_jacobian_step;
1156
1157 // Loop over the internal data
1158 for (unsigned i = 0; i < n_internal_data; i++)
1159 {
1160 // If we are doing all finite differences or
1161 // the variable is included in the finite difference loop, do it
1163 {
1164 // Get the number of value at the internal data
1165 const unsigned n_value = internal_data_pt(i)->nvalue();
1166
1167 // Loop over the number of values
1168 for (unsigned j = 0; j < n_value; j++)
1169 {
1170 // Get the local equation number
1172 // If it's not pinned
1173 if (local_unknown >= 0)
1174 {
1175 // Get a pointer to the value of the internal data
1176 double* const value_pt = internal_data_pt(i)->value_pt(j);
1177
1178 // Save the old value of the Internal data
1179 const double old_var = *value_pt;
1180
1181 // Increment the value of the Internal data
1182 *value_pt += fd_step;
1183
1184 // Now update any dependent variables
1186
1187 // Calculate the new residuals
1189
1190 // Do finite differences
1191 for (unsigned m = 0; m < n_dof; m++)
1192 {
1193 double sum = (newres[m] - residuals[m]) / fd_step;
1194 // Stick the entry into the Jacobian matrix
1195 jacobian(m, local_unknown) = sum;
1196 }
1197
1198 // Reset the Internal data
1199 *value_pt = old_var;
1200
1201 // Reset any dependent variables
1203 }
1204 }
1205 } // End of finite-differencing for datum (if block)
1206 }
1207
1208 // End of finite difference loop
1209 // Final reset of any dependent data
1211 }
1212
1213 //============================================================================
1214 /// This function calculates the entries of Jacobian matrix, used in
1215 /// the Newton method, associated with the external degrees of freedom.
1216 /// It does this using finite differences,
1217 /// rather than an analytical formulation, so can be done in total generality.
1218 /// If the boolean argument is true, the finite
1219 /// differencing will be performed for all internal data, irrespective of
1220 /// the information in Data_fd. The default value (false)
1221 /// uses the information in Data_fd to selectively difference only
1222 /// certain data.
1223 //==========================================================================
1226 DenseMatrix<double>& jacobian,
1227 const bool& fd_all_data)
1228 {
1229 // Locally cache the number of external data
1230 const unsigned n_external_data = Nexternal_data;
1231 // If there aren't any external data, then return straight away
1232 if (n_external_data == 0)
1233 {
1234 return;
1235 }
1236
1237 // Call the update function to ensure that the element is in
1238 // a consistent state before finite differencing starts
1240
1241 // Find the number of dofs in the element
1242 const unsigned n_dof = ndof();
1243
1244 // Create newres vector
1246
1247 // Integer storage for local unknown
1248 int local_unknown = 0;
1249
1250 // Use the default finite difference step
1251 const double fd_step = Default_fd_jacobian_step;
1252
1253 // Loop over the external data
1254 for (unsigned i = 0; i < n_external_data; i++)
1255 {
1256 // If we are doing all finite differences or
1257 // the variable is included in the finite difference loop, do it
1259 {
1260 // Get the number of value at the external data
1261 const unsigned n_value = external_data_pt(i)->nvalue();
1262
1263 // Loop over the number of values
1264 for (unsigned j = 0; j < n_value; j++)
1265 {
1266 // Get the local equation number
1268 // If it's not pinned
1269 if (local_unknown >= 0)
1270 {
1271 // Get a pointer to the External data value
1272 double* const value_pt = external_data_pt(i)->value_pt(j);
1273
1274 // Save the old value of the External data
1275 const double old_var = *value_pt;
1276
1277 // Increment the value of the External data
1278 *value_pt += fd_step;
1279
1280 // Now update any dependent variables
1282
1283 // Calculate the new residuals
1285
1286 // Do finite differences
1287 for (unsigned m = 0; m < n_dof; m++)
1288 {
1289 double sum = (newres[m] - residuals[m]) / fd_step;
1290 // Stick the entry into the Jacobian matrix
1291 jacobian(m, local_unknown) = sum;
1292 }
1293
1294 // Reset the External data
1295 *value_pt = old_var;
1296
1297 // Reset any dependent variables
1299 }
1300 }
1301 } // End of finite differencing for datum (if block)
1302 }
1303
1304 // End of finite difference loop
1305 // Final reset of any dependent data
1307 }
1308
1309 //=====================================================================
1310 /// Add the elemental contribution to the mass matrix
1311 /// and the residuals vector. Note that
1312 /// this function will NOT initialise the residuals vector or the mass
1313 /// matrix. It must be called after the residuals vector and
1314 /// jacobian matrix have been initialised to zero. The default
1315 /// is deliberately broken.
1316 //=====================================================================
1319 {
1320 std::string error_message =
1321 "Empty fill_in_contribution_to_mass_matrix() has been called.\n";
1322 error_message +=
1323 "This function is called from the default implementation of\n";
1324 error_message += "get_mass_matrix();\n";
1325 error_message += "and must calculate the residuals vector and mass matrix ";
1326 error_message += "without initialising any of their entries.\n\n";
1327
1328 error_message +=
1329 "If you do not wish to use these defaults, you must overload\n";
1330 error_message += "get_mass_matrix(), which must initialise the entries\n";
1331 error_message += "of the residuals vector and mass matrix to zero.\n";
1332
1333 throw OomphLibError(
1334 error_message,
1335 "GeneralisedElement::fill_in_contribution_to_mass_matrix()",
1337 }
1338
1339 //=====================================================================
1340 /// Add the elemental contribution to the jacobian matrix,
1341 /// mass matrix and the residuals vector. Note that
1342 /// this function should NOT initialise any entries.
1343 /// It must be called after the residuals vector and
1344 /// matrices have been initialised to zero. The default is deliberately
1345 /// broken.
1346 //=====================================================================
1349 DenseMatrix<double>& jacobian,
1351 {
1352 std::string error_message =
1353 "Empty fill_in_contribution_to_jacobian_and_mass_matrix() has been ";
1354 error_message += "called.\n";
1355 error_message +=
1356 "This function is called from the default implementation of\n";
1357 error_message += "get_jacobian_and_mass_matrix();\n";
1358 error_message +=
1359 "and must calculate the residuals vector and mass and jacobian matrices ";
1360 error_message += "without initialising any of their entries.\n\n";
1361
1362 error_message +=
1363 "If you do not wish to use these defaults, you must overload\n";
1364 error_message +=
1365 "get_jacobian_and_mass_matrix(), which must initialise the entries\n";
1366 error_message +=
1367 "of the residuals vector, jacobian and mass matrix to zero.\n";
1368
1369 throw OomphLibError(
1370 error_message,
1371 "GeneralisedElement::fill_in_contribution_to_jacobian_and_mass_matrix()",
1373 }
1374
1375
1376 //=====================================================================
1377 /// Add the elemental contribution to the derivatives of
1378 /// the residuals with respect to a parameter. This function should
1379 /// NOT initialise any entries and must be called after the entries
1380 /// have been initialised to zero
1381 /// The default implementation is deliberately broken
1382 //========================================================================
1384 double* const& parameter_pt, Vector<double>& dres_dparam)
1385 {
1386 std::string error_message =
1387 "Empty fill_in_contribution_to_dresiduals_dparameter() has been ";
1388 error_message += "called.\n";
1389 error_message +=
1390 "This function is called from the default implementation of\n";
1391 error_message += "get_dresiduals_dparameter();\n";
1392 error_message += "and must calculate the derivatives of the residuals "
1393 "vector with respect\n";
1394 error_message += "to the passed parameter ";
1395 error_message += "without initialising any values.\n\n";
1396
1397 error_message +=
1398 "If you do not wish to use these defaults, you must overload\n";
1399 error_message +=
1400 "get_dresiduals_dparameter(), which must initialise the entries\n";
1401 error_message += "of the returned vector to zero.\n";
1402
1403 error_message +=
1404 "This function is intended for use instead of the default (global) \n";
1405 error_message +=
1406 "finite-difference routine when analytic expressions are to be used\n";
1407 error_message += "in continuation and bifurcation tracking problems.\n\n";
1408 error_message += "This function is only called when the function\n";
1409 error_message +=
1410 "Problem::set_analytic_dparameter() has been called in the driver code\n";
1411
1412 throw OomphLibError(
1413 error_message,
1414 "GeneralisedElement::fill_in_contribution_to_dresiduals_dparameter()",
1416 }
1417
1418 //======================================================================
1419 /// Add the elemental contribution to the derivatives of
1420 /// the elemental Jacobian matrix
1421 /// and residuals with respect to a parameter. This function should
1422 /// NOT initialise any entries and must be called after the entries
1423 /// have been initialised to zero
1424 /// The default implementation is to use finite differences to calculate
1425 /// the derivatives.
1426 //========================================================================
1428 double* const& parameter_pt,
1431 {
1432 std::string error_message =
1433 "Empty fill_in_contribution_to_djacobian_dparameter() has been ";
1434 error_message += "called.\n";
1435 error_message +=
1436 "This function is called from the default implementation of\n";
1437 error_message += "get_djacobian_dparameter();\n";
1438 error_message +=
1439 "and must calculate the derivatives of residuals vector and jacobian ";
1440 error_message += "matrix\n";
1441 error_message += "with respect to the passed parameter ";
1442 error_message += "without initialising any values.\n\n";
1443
1444 error_message +=
1445 "If you do not wish to use these defaults, you must overload\n";
1446 error_message +=
1447 "get_djacobian_dparameter(), which must initialise the entries\n";
1448 error_message += "of the returned vector and matrix to zero.\n\n";
1449
1450 error_message +=
1451 "This function is intended for use instead of the default (global) \n";
1452 error_message +=
1453 "finite-difference routine when analytic expressions are to be used\n";
1454 error_message += "in continuation and bifurcation tracking problems.\n\n";
1455 error_message += "This function is only called when the function\n";
1456 error_message +=
1457 "Problem::set_analytic_dparameter() has been called in the driver code\n";
1458
1459
1460 throw OomphLibError(
1461 error_message,
1462 "GeneralisedElement::fill_in_contribution_to_djacobian_dparameter()",
1464 }
1465
1466
1467 //=====================================================================
1468 /// Add the elemental contribution to the derivative of the
1469 /// jacobian matrix,
1470 /// mass matrix and the residuals vector with respect to a parameter.
1471 /// Note that
1472 /// this function should NOT initialise any entries.
1473 /// It must be called after the residuals vector and
1474 /// matrices have been initialised to zero. The default is deliberately
1475 /// broken.
1476 //=====================================================================
1479 double* const& parameter_pt,
1483 {
1484 std::string error_message =
1485 "Empty fill_in_contribution_to_djacobian_and_dmass_matrix_dparameter() "
1486 "has";
1487 error_message += " been called.\n";
1488 error_message +=
1489 "This function is called from the default implementation of\n";
1490 error_message += "get_djacobian_and_dmass_matrix_dparameter();\n";
1491 error_message +=
1492 "and must calculate the residuals vector and mass and jacobian matrices ";
1493 error_message += "without initialising any of their entries.\n\n";
1494
1495 error_message +=
1496 "If you do not wish to use these defaults, you must overload\n";
1497 error_message += "get_djacobian_and_dmass_matrix_dparameter(), which must "
1498 "initialise the\n";
1499 error_message += "entries of the returned vector and matrices to zero.\n";
1500
1501
1502 error_message +=
1503 "This function is intended for use instead of the default (global) \n";
1504 error_message +=
1505 "finite-difference routine when analytic expressions are to be used\n";
1506 error_message += "in continuation and bifurcation tracking problems.\n\n";
1507 error_message += "This function is only called when the function\n";
1508 error_message +=
1509 "Problem::set_analytic_dparameter() has been called in the driver code\n";
1510
1511
1512 throw OomphLibError(error_message,
1513 "GeneralisedElement::fill_in_contribution_to_djacobian_"
1514 "and_dmass_matrix_dparameter()",
1516 }
1517
1518
1519 //========================================================================
1520 /// Fill in contribution to the product of the Hessian
1521 /// (derivative of Jacobian with
1522 /// respect to all variables) an eigenvector, Y, and
1523 /// other specified vectors, C
1524 /// (d(J_{ij})/d u_{k}) Y_{j} C_{k}
1525 /// At the moment the dof pointer is passed in to enable
1526 /// easy calculation of finite difference default
1527 //==========================================================================
1529 Vector<double> const& Y,
1530 DenseMatrix<double> const& C,
1532 {
1533 std::string error_message =
1534 "Empty fill_in_contribution_to_hessian_vector_products() has been ";
1535 error_message += "called.\n";
1536 error_message +=
1537 "This function is called from the default implementation of\n";
1538 error_message += "get_hessian_vector_products(); ";
1539 error_message += " and must calculate the products \n";
1540 error_message += "of the hessian matrix with the (global) ";
1541 error_message += "vectors Y and C\n";
1542 error_message += "without initialising any values.\n\n";
1543
1544 error_message +=
1545 "If you do not wish to use these defaults, you must overload\n";
1546 error_message +=
1547 "get_hessian_vector_products(), which must initialise the entries\n";
1548 error_message += "of the returned vector to zero.\n\n";
1549
1550 error_message +=
1551 "This function is intended for use instead of the default (global) \n";
1552 error_message +=
1553 "finite-difference routine when analytic expressions are to be used.\n";
1554 error_message += "This function is only called when the function\n";
1555 error_message += "Problem::set_analytic_hessian_products() has been called "
1556 "in the driver code\n";
1557
1558 throw OomphLibError(
1559 error_message,
1560 "GeneralisedElement::fill_in_contribution_to_hessian_vector_product()",
1562 }
1563
1564 //========================================================================
1565 /// Fill in the contribution to the inner products between given
1566 /// pairs of history values
1567 //==========================================================================
1569 Vector<std::pair<unsigned, unsigned>> const& history_index,
1571 {
1572 std::string error_message =
1573 "Empty fill_in_contribution_to_inner_products() has been called.\n";
1574 error_message +=
1575 "This function is called from the default implementation of\n";
1576 error_message += "get_inner_products();\n ";
1577 error_message += "It must calculate the inner products over the element\n";
1578 error_message += "of given pairs of history values\n";
1579 error_message += "without initialision of the output vector.\n\n";
1580
1581 error_message +=
1582 "If you do not wish to use these defaults, you must overload\n";
1583 error_message +=
1584 "get_inner_products(), which must initialise the entries\n";
1585 error_message += "of the returned vector to zero.\n\n";
1586
1587 throw OomphLibError(
1589 }
1590
1591 //========================================================================
1592 /// Fill in the contributions to the vectors that when taken
1593 /// as dot product with other history values give the inner product
1594 /// over the element
1595 //==========================================================================
1599 {
1600 std::string error_message =
1601 "Empty fill_in_contribution_to_inner_product_vectors() has been "
1602 "called.\n";
1603 error_message +=
1604 "This function is called from the default implementation of\n";
1605 error_message += "get_inner_product_vectors(); ";
1606 error_message += " and must calculate the vectors \n";
1607 error_message += "corresponding to the input history values\n ";
1608 error_message +=
1609 "that when multiplied by other vectors of history values\n";
1610 error_message += "return the appropriate dot products.\n\n";
1611 error_message += "The output vectors must not be initialised.\n\n";
1612
1613 error_message +=
1614 "If you do not wish to use these defaults, you must overload\n";
1615 error_message +=
1616 "get_inner_products(), which must initialise the entries\n";
1617 error_message += "of the returned vector to zero.\n\n";
1618
1619 throw OomphLibError(
1621 }
1622
1623
1624 //==========================================================================
1625 /// Self-test: Have all internal values been classified as
1626 /// pinned/unpinned? Return 0 if OK.
1627 //==========================================================================
1629 {
1630 // Initialise
1631 bool passed = true;
1632
1633 // Loop over internal Data
1634 for (unsigned i = 0; i < Ninternal_data; i++)
1635 {
1636 if (internal_data_pt(i)->self_test() != 0)
1637 {
1638 passed = false;
1639 oomph_info << "\n ERROR: Failed GeneralisedElement::self_test()!"
1640 << std::endl;
1641 oomph_info << "for internal data object number: " << i << std::endl;
1642 }
1643 }
1644
1645 // Loop over external Data
1646 for (unsigned i = 0; i < Nexternal_data; i++)
1647 {
1648 if (external_data_pt(i)->self_test() != 0)
1649 {
1650 passed = false;
1651 oomph_info << "\n ERROR: Failed GeneralisedElement::self_test()!"
1652 << std::endl;
1653 oomph_info << "for external data object number: " << i << std::endl;
1654 }
1655 }
1656
1657 // Return verdict
1658 if (passed)
1659 {
1660 return 0;
1661 }
1662 else
1663 {
1664 return 1;
1665 }
1666 }
1667
1668
1669 //======================================================================
1670 /// Helper namespace for tolerances, number of iterations, etc
1671 /// used in the locate_zeta function in FiniteElement
1672 //======================================================================
1673 namespace Locate_zeta_helpers
1674 {
1675 /// Convergence tolerance for the newton solver
1676 double Newton_tolerance = 1.0e-7;
1677
1678 /// Maximum number of newton iterations
1680
1681 /// Multiplier for (zeta-based) outer radius of element used for
1682 /// deciding that point is outside element. Set to negative value
1683 /// to suppress test.
1685
1686 /// Number of points along one dimension of each element used
1687 /// to create coordinates within the element in order to see
1688 /// which has the smallest initial residual (and is therefore used
1689 /// as the initial guess in the Newton method when locating coordinate)
1690 unsigned N_local_points = 5;
1691 } // namespace Locate_zeta_helpers
1692
1693
1694 ///////////////////////////////////////////////////////////////////////////
1695 ///////////////////////////////////////////////////////////////////////////
1696 // Functions for finite elements
1697 ///////////////////////////////////////////////////////////////////////////
1698 ///////////////////////////////////////////////////////////////////////////
1699
1700 //======================================================================
1701 /// Return the i-th coordinate at local node n. Do not use
1702 /// the hanging node representation.
1703 /// NOTE: Moved to cc file because of a possible compiler bug
1704 /// in gcc (yes, really!). The move to the cc file avoids inlining
1705 /// which appears to cause problems (only) when compiled with gcc
1706 /// and -O3; offensive "illegal read" is in optimised-out section
1707 /// of code and data that is allegedly illegal is readily readable
1708 /// (by other means) just before this function is called so I can't
1709 /// really see how we could possibly be responsible for this...
1710 //======================================================================
1711 double FiniteElement::raw_nodal_position(const unsigned& n,
1712 const unsigned& i) const
1713 {
1714 /* oomph_info << "n: "<< n << std::endl; */
1715 /* oomph_info << "i: "<< i << std::endl; */
1716 /* oomph_info << "node_pt(n): "<< node_pt(n) << std::endl; */
1717 /* oomph_info << "node_pt(n)->x(i): "<< node_pt(n)->x(i) << std::endl; */
1718 // double tmp=node_pt(n)->x(i);
1719 // oomph_info << "tmp: "<< tmp << std::endl;
1720 return node_pt(n)->x(i);
1721 }
1722
1723
1724 //======================================================================
1725 /// Function to describe the local dofs of the element. The ostream
1726 /// specifies the output stream to which the description
1727 /// is written; the string stores the currently
1728 /// assembled output that is ultimately written to the
1729 /// output stream by Data::describe_dofs(...); it is typically
1730 /// built up incrementally as we descend through the
1731 /// call hierarchy of this function when called from
1732 /// Problem::describe_dofs(...)
1733 //======================================================================
1735 std::ostream& out, const std::string& current_string) const
1736 {
1737 // Call the standard finite element classification.
1740 }
1741
1742 //======================================================================
1743 /// Function to describe the local dofs of the element. The ostream
1744 /// specifies the output stream to which the description
1745 /// is written; the string stores the currently
1746 /// assembled output that is ultimately written to the
1747 /// output stream by Data::describe_dofs(...); it is typically
1748 /// built up incrementally as we descend through the
1749 /// call hierarchy of this function when called from
1750 /// Problem::describe_dofs(...)
1751 //======================================================================
1753 std::ostream& out, const std::string& current_string) const
1754 {
1755 // Find the number of nodes
1756 const unsigned n_node = nnode();
1757 for (unsigned n = 0; n < n_node; n++)
1758 {
1759 // Pointer to node
1760 Node* const nod_pt = node_pt(n);
1761
1762 std::stringstream conversion;
1763 conversion << " of Node " << n << current_string;
1764 std::string in(conversion.str());
1766 } // End if for n_node
1767 } // End describe_nodal_local_dofs
1768
1769 //========================================================================
1770 /// Internal function used to check for singular or negative values
1771 /// of the determinant of the Jacobian of the mapping between local and
1772 /// global or lagrangian coordinates. Negative jacobians are allowed if the
1773 /// Accept_negative_jacobian flag is set to true.
1774 //========================================================================
1775 void FiniteElement::check_jacobian(const double& jacobian) const
1776 {
1777 // First check for a zero jacobian
1778 if (std::fabs(jacobian) < Tolerance_for_singular_jacobian)
1779 {
1781 {
1782 throw OomphLibQuietException();
1783 }
1784 else
1785 {
1786 std::ostringstream error_stream;
1788 << "Determinant of Jacobian matrix is zero --- "
1789 << "singular mapping!\nThe determinant of the "
1790 << "jacobian is " << std::fabs(jacobian)
1791 << " which is smaller than the treshold "
1793 << "You can change this treshold, by specifying "
1794 << "FiniteElement::Tolerance_for_singular_jacobian \n"
1795 << "Here are the nodal coordinates of the inverted element\n"
1796 << "in the form \n\n x,y[,z], hang_status\n\n"
1797 << "where hang_status = 1 or 2 for non-hanging or hanging\n"
1798 << "nodes respectively (useful for automatic sizing of\n"
1799 << "tecplot markers to identify the hanging nodes). \n\n";
1800 unsigned n_dim_nod = node_pt(0)->ndim();
1801 unsigned n_nod = nnode();
1802 unsigned hang_count = 0;
1803 for (unsigned j = 0; j < n_nod; j++)
1804 {
1805 for (unsigned i = 0; i < n_dim_nod; i++)
1806 {
1807 error_stream << node_pt(j)->x(i) << " ";
1808 }
1809 if (node_pt(j)->is_hanging())
1810 {
1811 error_stream << " 2";
1812 hang_count++;
1813 }
1814 else
1815 {
1816 error_stream << " 1";
1817 }
1818 error_stream << std::endl;
1819 }
1820 error_stream << std::endl << std::endl;
1821 if ((Macro_elem_pt != 0) && (0 != hang_count))
1822 {
1824 << "NOTE: Offending element is associated with a MacroElement\n"
1825 << " AND the element has hanging nodes! \n"
1826 << " If an element is thin and highly curved, the \n"
1827 << " constraints imposed by\n \n"
1828 << " (1) inter-element continuity (imposed by the hanging\n"
1829 << " node constraints) and \n\n"
1830 << " (2) the need to respect curvilinear domain boundaries\n"
1831 << " during mesh refinement (imposed by the element's\n"
1832 << " macro element mapping)\n\n"
1833 << " may be irreconcilable! \n \n"
1834 << " You may have to re-design your base mesh to avoid \n"
1835 << " the creation of thin, highly curved elements during\n"
1836 << " the refinement process.\n"
1837 << std::endl;
1838 }
1839 throw OomphLibError(
1841 }
1842 }
1843
1844
1845 // Now check for negative jacobians, if we're not allowing them (default)
1846 if ((Accept_negative_jacobian == false) && (jacobian < 0.0))
1847 {
1849 {
1850 throw OomphLibQuietException();
1851 }
1852 else
1853 {
1854 std::ostringstream error_stream;
1855 error_stream << "Negative Jacobian in transform from "
1856 << "local to global coordinates" << std::endl
1857 << " You have an inverted coordinate system!"
1858 << std::endl
1859 << std::endl;
1861 << "Here are the nodal coordinates of the inverted element\n"
1862 << "in the form \n\n x,y[,z], hang_status\n\n"
1863 << "where hang_status = 1 or 2 for non-hanging or hanging\n"
1864 << "nodes respectively (useful for automatic sizing of\n"
1865 << "tecplot markers to identify the hanging nodes). \n\n";
1866 unsigned n_dim_nod = node_pt(0)->ndim();
1867 unsigned n_nod = nnode();
1868 unsigned hang_count = 0;
1869 for (unsigned j = 0; j < n_nod; j++)
1870 {
1871 for (unsigned i = 0; i < n_dim_nod; i++)
1872 {
1873 error_stream << node_pt(j)->x(i) << " ";
1874 }
1875 if (node_pt(j)->is_hanging())
1876 {
1877 error_stream << " 2";
1878 hang_count++;
1879 }
1880 else
1881 {
1882 error_stream << " 1";
1883 }
1884 error_stream << std::endl;
1885 }
1886 error_stream << std::endl << std::endl;
1887 if ((Macro_elem_pt != 0) && (0 != hang_count))
1888 {
1890 << "NOTE: The inverted element is associated with a MacroElement\n"
1891 << " AND the element has hanging nodes! \n"
1892 << " If an element is thin and highly curved, the \n"
1893 << " constraints imposed by\n \n"
1894 << " (1) inter-element continuity (imposed by the hanging\n"
1895 << " node constraints) and \n\n"
1896 << " (2) the need to respect curvilinear domain boundaries\n"
1897 << " during mesh refinement (imposed by the element's\n"
1898 << " macro element mapping)\n\n"
1899 << " may be irreconcilable! \n \n"
1900 << " You may have to re-design your base mesh to avoid \n"
1901 << " the creation of thin, highly curved elements during\n"
1902 << " the refinement process.\n"
1903 << std::endl;
1904 }
1905
1907 << std::endl
1908 << std::endl
1909 << "If you believe that inverted elements do not cause any\n"
1910 << "problems in your specific application you can \n "
1911 << "suppress this test by: " << std::endl
1912 << " i) setting the (static) flag "
1913 << "FiniteElement::Accept_negative_jacobian to be true" << std::endl;
1914 error_stream << " ii) switching OFF the PARANOID flag" << std::endl
1915 << std::endl;
1916
1917 // Throw an inverted error so it can be caught by the adaptive
1918 // timestepper and arc length continuation for example.
1921 }
1922 }
1923 }
1924
1925 //=========================================================================
1926 /// Internal function that is used to assemble the jacobian of the mapping
1927 /// from local coordinates (s) to the eulerian coordinates (x), given the
1928 /// derivatives of the shape functions. The entire jacobian matrix is
1929 /// constructed and this function will only work if there are the same number
1930 /// of local coordinates as global coordinates (i.e. for "bulk" elements).
1931 //=========================================================================
1933 const DShape& dpsids, DenseMatrix<double>& jacobian) const
1934 {
1935 // Locally cache the elemental dimension
1936 const unsigned el_dim = dim();
1937 // The number of shape functions must be equal to the number
1938 // of nodes (by definition)
1939 const unsigned n_shape = nnode();
1940 // The number of shape function types must be equal to the number
1941 // of nodal position types (by definition)
1942 const unsigned n_shape_type = nnodal_position_type();
1943
1944#ifdef PARANOID
1945 // Check for dimensional compatibility
1947 {
1948 std::ostringstream error_message;
1949 error_message << "Dimension mismatch" << std::endl;
1950 error_message << "The elemental dimension: " << Elemental_dimension
1951 << " must equal the nodal dimension: " << Nodal_dimension
1952 << " for the jacobian of the mapping to be well-defined"
1953 << std::endl;
1954 throw OomphLibError(
1955 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1956 }
1957#endif
1958
1959
1960 // Loop over the rows of the jacobian
1961 for (unsigned i = 0; i < el_dim; i++)
1962 {
1963 // Loop over the columns of the jacobian
1964 for (unsigned j = 0; j < el_dim; j++)
1965 {
1966 // Zero the entry
1967 jacobian(i, j) = 0.0;
1968 // Loop over the shape functions
1969 for (unsigned l = 0; l < n_shape; l++)
1970 {
1971 for (unsigned k = 0; k < n_shape_type; k++)
1972 {
1973 // Jacobian is dx_j/ds_i, which is represented by the sum
1974 // over the dpsi/ds_i of the nodal points X j
1975 // Call the Non-hanging version of positions
1976 // This is overloaded in refineable elements
1977 jacobian(i, j) += raw_nodal_position_gen(l, k, j) * dpsids(l, k, i);
1978 }
1979 }
1980 }
1981 }
1982 }
1983
1984 //=========================================================================
1985 /// Internal function that is used to assemble the jacobian of second
1986 /// derivatives of the mapping from local coordinates (s) to the
1987 /// eulerian coordinates (x), given the second derivatives of the
1988 /// shape functions.
1989 //=========================================================================
1992 {
1993 // Find the dimension of the element
1994 const unsigned el_dim = dim();
1995 // Find the number of shape functions and shape functions types
1996 // Must be equal to the number of nodes and their position types
1997 // by the definition of the shape function.
1998 const unsigned n_shape = nnode();
1999 const unsigned n_shape_type = nnodal_position_type();
2000 // Find the number of second derivatives
2001 const unsigned n_row = N2deriv[el_dim];
2002
2003 // Assemble the "jacobian" (d^2 x_j/ds_i^2) for second derivatives of
2004 // shape functions
2005 // Loop over the rows (number of second derivatives)
2006 for (unsigned i = 0; i < n_row; i++)
2007 {
2008 // Loop over the columns (element dimension
2009 for (unsigned j = 0; j < el_dim; j++)
2010 {
2011 // Zero the entry
2012 jacobian2(i, j) = 0.0;
2013 // Loop over the shape functions
2014 for (unsigned l = 0; l < n_shape; l++)
2015 {
2016 // Loop over the shape function types
2017 for (unsigned k = 0; k < n_shape_type; k++)
2018 {
2019 // Add the terms to the jacobian entry
2020 // Call the Non-hanging version of positions
2021 // This is overloaded in refineable elements
2022 jacobian2(i, j) +=
2024 }
2025 }
2026 }
2027 }
2028 }
2029
2030 //=====================================================================
2031 /// Assemble the covariant Eulerian base vectors and return them in the
2032 /// matrix interpolated_G. The derivatives of the shape functions with
2033 /// respect to the local coordinate should already have been calculated
2034 /// before calling this function
2035 //=====================================================================
2038 {
2039 // Find the number of nodes and position types
2040 const unsigned n_node = nnode();
2041 const unsigned n_position_type = nnodal_position_type();
2042 // Find the dimension of the node and element
2043 const unsigned n_dim_node = nodal_dimension();
2044 const unsigned n_dim_element = dim();
2045
2046 // Loop over the dimensions and compute the entries of the
2047 // base vector matrix
2048 for (unsigned i = 0; i < n_dim_element; i++)
2049 {
2050 for (unsigned j = 0; j < n_dim_node; j++)
2051 {
2052 // Initialise the j-th component of the i-th base vector to zero
2053 interpolated_G(i, j) = 0.0;
2054 for (unsigned l = 0; l < n_node; l++)
2055 {
2056 for (unsigned k = 0; k < n_position_type; k++)
2057 {
2058 interpolated_G(i, j) +=
2060 }
2061 }
2062 }
2063 }
2064 }
2065
2066
2067 //============================================================================
2068 /// Zero-d specialisation of function to calculate inverse of jacobian mapping
2069 //============================================================================
2070 template<>
2071 double FiniteElement::invert_jacobian<0>(
2072 const DenseMatrix<double>& jacobian,
2074 {
2075 // Issue a warning
2076 oomph_info << "\nWarning: You are trying to invert the jacobian for "
2077 << "a 'point' element" << std::endl
2078 << "This makes no sense and is almost certainly an error"
2079 << std::endl
2080 << std::endl;
2081
2082 // Dummy return
2083 return (1.0);
2084 }
2085
2086
2087 //===========================================================================
2088 /// One-d specialisation of function to calculate inverse of jacobian mapping
2089 //===========================================================================
2090 template<>
2091 double FiniteElement::invert_jacobian<1>(
2092 const DenseMatrix<double>& jacobian,
2094 {
2095 // Calculate the determinant of the matrix
2096 const double det = jacobian(0, 0);
2097
2098// Report if Matrix is singular or negative
2099#ifdef PARANOID
2101#endif
2102
2103 // Calculate the inverse --- trivial in 1D
2104 inverse_jacobian(0, 0) = 1.0 / jacobian(0, 0);
2105
2106 // Return the determinant
2107 return (det);
2108 }
2109
2110 //===========================================================================
2111 /// Two-d specialisation of function to calculate inverse of jacobian mapping
2112 //===========================================================================
2113 template<>
2114 double FiniteElement::invert_jacobian<2>(
2115 const DenseMatrix<double>& jacobian,
2117 {
2118 // Calculate the determinant of the matrix
2119 const double det =
2120 jacobian(0, 0) * jacobian(1, 1) - jacobian(0, 1) * jacobian(1, 0);
2121
2122// Report if Matrix is singular or negative
2123#ifdef PARANOID
2125#endif
2126
2127 // Calculate the inverset of the 2x2 matrix
2128 inverse_jacobian(0, 0) = jacobian(1, 1) / det;
2129 inverse_jacobian(0, 1) = -jacobian(0, 1) / det;
2130 inverse_jacobian(1, 0) = -jacobian(1, 0) / det;
2131 inverse_jacobian(1, 1) = jacobian(0, 0) / det;
2132
2133 // Return the jacobian
2134 return (det);
2135 }
2136
2137 //=============================================================================
2138 /// Three-d specialisation of function to calculate inverse of jacobian
2139 /// mapping
2140 //=============================================================================
2141 template<>
2142 double FiniteElement::invert_jacobian<3>(
2143 const DenseMatrix<double>& jacobian,
2145 {
2146 // Calculate the determinant of the matrix
2147 const double det = jacobian(0, 0) * jacobian(1, 1) * jacobian(2, 2) +
2148 jacobian(0, 1) * jacobian(1, 2) * jacobian(2, 0) +
2149 jacobian(0, 2) * jacobian(1, 0) * jacobian(2, 1) -
2150 jacobian(0, 0) * jacobian(1, 2) * jacobian(2, 1) -
2151 jacobian(0, 1) * jacobian(1, 0) * jacobian(2, 2) -
2152 jacobian(0, 2) * jacobian(1, 1) * jacobian(2, 0);
2153
2154 // Report if Matrix is singular or negative
2155#ifdef PARANOID
2157#endif
2158
2159 // Calculate the inverse of the 3x3 matrix
2160 inverse_jacobian(0, 0) =
2161 (jacobian(1, 1) * jacobian(2, 2) - jacobian(1, 2) * jacobian(2, 1)) / det;
2162 inverse_jacobian(0, 1) =
2163 -(jacobian(0, 1) * jacobian(2, 2) - jacobian(0, 2) * jacobian(2, 1)) /
2164 det;
2165 inverse_jacobian(0, 2) =
2166 (jacobian(0, 1) * jacobian(1, 2) - jacobian(0, 2) * jacobian(1, 1)) / det;
2167 inverse_jacobian(1, 0) =
2168 -(jacobian(1, 0) * jacobian(2, 2) - jacobian(1, 2) * jacobian(2, 0)) /
2169 det;
2170 inverse_jacobian(1, 1) =
2171 (jacobian(0, 0) * jacobian(2, 2) - jacobian(0, 2) * jacobian(2, 0)) / det;
2172 inverse_jacobian(1, 2) =
2173 -(jacobian(0, 0) * jacobian(1, 2) - jacobian(0, 2) * jacobian(1, 0)) /
2174 det;
2175 inverse_jacobian(2, 0) =
2176 (jacobian(1, 0) * jacobian(2, 1) - jacobian(1, 1) * jacobian(2, 0)) / det;
2177 inverse_jacobian(2, 1) =
2178 -(jacobian(0, 0) * jacobian(2, 1) - jacobian(0, 1) * jacobian(2, 0)) /
2179 det;
2180 inverse_jacobian(2, 2) =
2181 (jacobian(0, 0) * jacobian(1, 1) - jacobian(0, 1) * jacobian(1, 0)) / det;
2182
2183 // Return the determinant
2184 return (det);
2185 }
2186
2187 //========================================================================
2188 /// Template-free interface for inversion of the jacobian of a mapping.
2189 /// This is slightly inefficient, given that it uses a switch statement.
2190 /// It can always be overloaded in specific geometric elements,
2191 /// for efficiency reasons.
2192 //========================================================================
2194 const DenseMatrix<double>& jacobian,
2196 {
2197 // Find the spatial dimension of the element
2198 const unsigned el_dim = dim();
2199 // Call the appropriate templated function, depending on the
2200 // element dimension
2201 switch (el_dim)
2202 {
2203 case 0:
2204 return invert_jacobian<0>(jacobian, inverse_jacobian);
2205 break;
2206 case 1:
2207 return invert_jacobian<1>(jacobian, inverse_jacobian);
2208 break;
2209 case 2:
2210 return invert_jacobian<2>(jacobian, inverse_jacobian);
2211 break;
2212 case 3:
2213 return invert_jacobian<3>(jacobian, inverse_jacobian);
2214 break;
2215 // Catch-all default case: issue warning and die
2216 default:
2217 std::ostringstream error_stream;
2218 error_stream << "Dimension of the element must be 0,1,2 or 3, not "
2219 << el_dim << std::endl;
2220
2221 throw OomphLibError(
2223 }
2224 // Dummy return for Intel compiler
2225 return 1.0;
2226 }
2227
2228 //============================================================================
2229 /// Zero-d specialisation of function to calculate the derivative of the
2230 /// jacobian of a mapping with respect to the nodal coordinates X_ij.
2231 //============================================================================
2232 template<>
2233 void FiniteElement::dJ_eulerian_dnodal_coordinates_templated_helper<0>(
2234 const DenseMatrix<double>& jacobian,
2235 const DShape& dpsids,
2237 {
2238 // Issue a warning
2239 oomph_info << "\nWarning: You are trying to calculate derivatives of "
2240 << "a jacobian w.r.t. nodal coordinates for a 'point' "
2241 << "element." << std::endl
2242 << "This makes no sense and is almost certainly an error."
2243 << std::endl
2244 << std::endl;
2245 }
2246
2247 //===========================================================================
2248 /// One-d specialisation of function to calculate the derivative of the
2249 /// jacobian of a mapping with respect to the nodal coordinates X_ij.
2250 //===========================================================================
2251 template<>
2252 void FiniteElement::dJ_eulerian_dnodal_coordinates_templated_helper<1>(
2253 const DenseMatrix<double>& jacobian,
2254 const DShape& dpsids,
2256 {
2257 // Determine the number of nodes in the element
2258 const unsigned n_node = nnode();
2259
2260 // Loop over nodes
2261 for (unsigned j = 0; j < n_node; j++)
2262 {
2263 djacobian_dX(0, j) = dpsids(j, 0);
2264 }
2265 }
2266
2267 //===========================================================================
2268 /// Two-d specialisation of function to calculate the derivative of the
2269 /// jacobian of a mapping with respect to the nodal coordinates X_ij.
2270 //===========================================================================
2271 template<>
2272 void FiniteElement::dJ_eulerian_dnodal_coordinates_templated_helper<2>(
2273 const DenseMatrix<double>& jacobian,
2274 const DShape& dpsids,
2276 {
2277 // Determine the number of nodes in the element
2278 const unsigned n_node = nnode();
2279
2280 // Loop over nodes
2281 for (unsigned j = 0; j < n_node; j++)
2282 {
2283 // i=0
2284 djacobian_dX(0, j) =
2285 dpsids(j, 0) * jacobian(1, 1) - dpsids(j, 1) * jacobian(0, 1);
2286
2287 // i=1
2288 djacobian_dX(1, j) =
2289 dpsids(j, 1) * jacobian(0, 0) - dpsids(j, 0) * jacobian(1, 0);
2290 }
2291 }
2292
2293 //=============================================================================
2294 /// Three-d specialisation of function to calculate the derivative of the
2295 /// jacobian of a mapping with respect to the nodal coordinates X_ij.
2296 //=============================================================================
2297 template<>
2298 void FiniteElement::dJ_eulerian_dnodal_coordinates_templated_helper<3>(
2299 const DenseMatrix<double>& jacobian,
2300 const DShape& dpsids,
2302 {
2303 // Determine the number of nodes in the element
2304 const unsigned n_node = nnode();
2305
2306 // Loop over nodes
2307 for (unsigned j = 0; j < n_node; j++)
2308 {
2309 // i=0
2310 djacobian_dX(0, j) =
2311 dpsids(j, 0) *
2312 (jacobian(1, 1) * jacobian(2, 2) - jacobian(1, 2) * jacobian(2, 1)) +
2313 dpsids(j, 1) *
2314 (jacobian(0, 2) * jacobian(2, 1) - jacobian(0, 1) * jacobian(2, 2)) +
2315 dpsids(j, 2) *
2316 (jacobian(0, 1) * jacobian(1, 2) - jacobian(0, 2) * jacobian(1, 1));
2317
2318 // i=1
2319 djacobian_dX(1, j) =
2320 dpsids(j, 0) *
2321 (jacobian(1, 2) * jacobian(2, 0) - jacobian(1, 0) * jacobian(2, 2)) +
2322 dpsids(j, 1) *
2323 (jacobian(0, 0) * jacobian(2, 2) - jacobian(0, 2) * jacobian(2, 0)) +
2324 dpsids(j, 2) *
2325 (jacobian(0, 2) * jacobian(1, 0) - jacobian(0, 0) * jacobian(1, 2));
2326
2327 // i=2
2328 djacobian_dX(2, j) =
2329 dpsids(j, 0) *
2330 (jacobian(1, 0) * jacobian(2, 1) - jacobian(1, 1) * jacobian(2, 0)) +
2331 dpsids(j, 1) *
2332 (jacobian(0, 1) * jacobian(2, 0) - jacobian(0, 0) * jacobian(2, 1)) +
2333 dpsids(j, 2) *
2334 (jacobian(0, 0) * jacobian(1, 1) - jacobian(0, 1) * jacobian(1, 0));
2335 }
2336 }
2337
2338 //============================================================================
2339 /// Zero-d specialisation of function to calculate the derivative w.r.t. the
2340 /// nodal coordinates \f$ X_{pq} \f$ of the derivative of the shape functions
2341 /// w.r.t. the global eulerian coordinates \f$ x_i \f$.
2342 //============================================================================
2343 template<>
2344 void FiniteElement::d_dshape_eulerian_dnodal_coordinates_templated_helper<0>(
2345 const double& det_jacobian,
2346 const DenseMatrix<double>& jacobian,
2349 const DShape& dpsids,
2351 {
2352 // Issue a warning
2353 oomph_info << "\nWarning: You are trying to calculate derivatives of "
2354 << "eulerian derivatives of shape functions w.r.t. nodal "
2355 << "coordinates for a 'point' element." << std::endl
2356 << "This makes no sense and is almost certainly an error."
2357 << std::endl
2358 << std::endl;
2359 }
2360
2361 //===========================================================================
2362 /// One-d specialisation of function to calculate the derivative w.r.t. the
2363 /// nodal coordinates \f$ X_{pq} \f$ of the derivative of the shape functions
2364 /// w.r.t. the global eulerian coordinates \f$ x_i \f$.
2365 //===========================================================================
2366 template<>
2367 void FiniteElement::d_dshape_eulerian_dnodal_coordinates_templated_helper<1>(
2368 const double& det_jacobian,
2369 const DenseMatrix<double>& jacobian,
2372 const DShape& dpsids,
2374 {
2375 // Find inverse of determinant of jacobian of mapping
2376 const double inv_det_jac = 1.0 / det_jacobian;
2377
2378 // Determine the number of nodes in the element
2379 const unsigned n_node = nnode();
2380
2381 // Loop over the shape functions
2382 for (unsigned q = 0; q < n_node; q++)
2383 {
2384 // Loop over the shape functions
2385 for (unsigned j = 0; j < n_node; j++)
2386 {
2387 d_dpsidx_dX(0, q, j, 0) =
2388 -djacobian_dX(0, q) * dpsids(j, 0) * inv_det_jac * inv_det_jac;
2389 }
2390 }
2391 }
2392
2393 //===========================================================================
2394 /// Two-d specialisation of function to calculate the derivative w.r.t. the
2395 /// nodal coordinates \f$ X_{pq} \f$ of the derivative of the shape functions
2396 /// w.r.t. the global eulerian coordinates \f$ x_i \f$.
2397 //===========================================================================
2398 template<>
2399 void FiniteElement::d_dshape_eulerian_dnodal_coordinates_templated_helper<2>(
2400 const double& det_jacobian,
2401 const DenseMatrix<double>& jacobian,
2404 const DShape& dpsids,
2406 {
2407 // Find inverse of determinant of jacobian of mapping
2408 const double inv_det_jac = 1.0 / det_jacobian;
2409
2410 // Determine the number of nodes in the element
2411 const unsigned n_node = nnode();
2412
2413 // Loop over the spatial dimension (this must be 2)
2414 for (unsigned p = 0; p < 2; p++)
2415 {
2416 // Loop over the shape functions
2417 for (unsigned q = 0; q < n_node; q++)
2418 {
2419 // Loop over the shape functions
2420 for (unsigned j = 0; j < n_node; j++)
2421 {
2422 // i=0
2423 d_dpsidx_dX(p, q, j, 0) =
2424 -djacobian_dX(p, q) * (inverse_jacobian(0, 0) * dpsids(j, 0) +
2425 inverse_jacobian(0, 1) * dpsids(j, 1));
2426
2427 if (p == 1)
2428 {
2429 d_dpsidx_dX(p, q, j, 0) +=
2430 dpsids(j, 0) * dpsids(q, 1) - dpsids(j, 1) * dpsids(q, 0);
2431 }
2432 d_dpsidx_dX(p, q, j, 0) *= inv_det_jac;
2433
2434 // i=1
2435 d_dpsidx_dX(p, q, j, 1) =
2436 -djacobian_dX(p, q) * (inverse_jacobian(1, 1) * dpsids(j, 1) +
2437 inverse_jacobian(1, 0) * dpsids(j, 0));
2438
2439 if (p == 0)
2440 {
2441 d_dpsidx_dX(p, q, j, 1) +=
2442 dpsids(j, 1) * dpsids(q, 0) - dpsids(j, 0) * dpsids(q, 1);
2443 }
2444 d_dpsidx_dX(p, q, j, 1) *= inv_det_jac;
2445 }
2446 }
2447 }
2448 }
2449
2450 //=============================================================================
2451 /// Three-d specialisation of function to calculate the derivative w.r.t. the
2452 /// nodal coordinates \f$ X_{pq} \f$ of the derivative of the shape functions
2453 /// w.r.t. the global eulerian coordinates \f$ x_i \f$.
2454 //=============================================================================
2455 template<>
2456 void FiniteElement::d_dshape_eulerian_dnodal_coordinates_templated_helper<3>(
2457 const double& det_jacobian,
2458 const DenseMatrix<double>& jacobian,
2461 const DShape& dpsids,
2463 {
2464 // Find inverse of determinant of jacobian of mapping
2465 const double inv_det_jac = 1.0 / det_jacobian;
2466
2467 // Determine the number of nodes in the element
2468 const unsigned n_node = nnode();
2469
2470 // Loop over the spatial dimension (this must be 3)
2471 for (unsigned p = 0; p < 3; p++)
2472 {
2473 // Loop over the shape functions
2474 for (unsigned q = 0; q < n_node; q++)
2475 {
2476 // Loop over the shape functions
2477 for (unsigned j = 0; j < n_node; j++)
2478 {
2479 // Terms not multiplied by delta function
2480 for (unsigned i = 0; i < 3; i++)
2481 {
2482 d_dpsidx_dX(p, q, j, i) =
2483 -djacobian_dX(p, q) * (inverse_jacobian(i, 0) * dpsids(j, 0) +
2484 inverse_jacobian(i, 1) * dpsids(j, 1) +
2485 inverse_jacobian(i, 2) * dpsids(j, 2));
2486 }
2487
2488 // Delta function terms
2489 switch (p)
2490 {
2491 case 0:
2492 d_dpsidx_dX(p, q, j, 1) += ((dpsids(q, 2) * jacobian(1, 2) -
2493 dpsids(q, 1) * jacobian(2, 2)) *
2494 dpsids(j, 0) +
2495 (dpsids(q, 0) * jacobian(2, 2) -
2496 dpsids(q, 2) * jacobian(0, 2)) *
2497 dpsids(j, 1) +
2498 (dpsids(q, 1) * jacobian(0, 2) -
2499 dpsids(q, 0) * jacobian(1, 2)) *
2500 dpsids(j, 2));
2501
2502 d_dpsidx_dX(p, q, j, 2) += ((dpsids(q, 1) * jacobian(2, 1) -
2503 dpsids(q, 2) * jacobian(1, 1)) *
2504 dpsids(j, 0) +
2505 (dpsids(q, 2) * jacobian(0, 1) -
2506 dpsids(q, 0) * jacobian(2, 1)) *
2507 dpsids(j, 1) +
2508 (dpsids(q, 0) * jacobian(1, 1) -
2509 dpsids(q, 1) * jacobian(0, 1)) *
2510 dpsids(j, 2));
2511 break;
2512
2513 case 1:
2514
2515 d_dpsidx_dX(p, q, j, 0) += ((dpsids(q, 1) * jacobian(2, 2) -
2516 dpsids(q, 2) * jacobian(1, 2)) *
2517 dpsids(j, 0) +
2518 (dpsids(q, 2) * jacobian(0, 2) -
2519 dpsids(q, 0) * jacobian(2, 2)) *
2520 dpsids(j, 1) +
2521 (dpsids(q, 0) * jacobian(1, 2) -
2522 dpsids(q, 1) * jacobian(0, 2)) *
2523 dpsids(j, 2));
2524
2525 d_dpsidx_dX(p, q, j, 2) += ((dpsids(q, 2) * jacobian(1, 0) -
2526 dpsids(q, 1) * jacobian(2, 0)) *
2527 dpsids(j, 0) +
2528 (dpsids(q, 0) * jacobian(2, 0) -
2529 dpsids(q, 2) * jacobian(0, 0)) *
2530 dpsids(j, 1) +
2531 (dpsids(q, 1) * jacobian(0, 0) -
2532 dpsids(q, 0) * jacobian(1, 0)) *
2533 dpsids(j, 2));
2534 break;
2535
2536 case 2:
2537
2538 d_dpsidx_dX(p, q, j, 0) += ((dpsids(q, 2) * jacobian(1, 1) -
2539 dpsids(q, 1) * jacobian(2, 1)) *
2540 dpsids(j, 0) +
2541 (dpsids(q, 0) * jacobian(2, 1) -
2542 dpsids(q, 2) * jacobian(0, 1)) *
2543 dpsids(j, 1) +
2544 (dpsids(q, 1) * jacobian(0, 1) -
2545 dpsids(q, 0) * jacobian(1, 1)) *
2546 dpsids(j, 2));
2547
2548 d_dpsidx_dX(p, q, j, 1) += ((dpsids(q, 1) * jacobian(2, 0) -
2549 dpsids(q, 2) * jacobian(1, 0)) *
2550 dpsids(j, 0) +
2551 (dpsids(q, 2) * jacobian(0, 0) -
2552 dpsids(q, 0) * jacobian(2, 0)) *
2553 dpsids(j, 1) +
2554 (dpsids(q, 0) * jacobian(1, 0) -
2555 dpsids(q, 1) * jacobian(0, 0)) *
2556 dpsids(j, 2));
2557 break;
2558 }
2559
2560 // Divide through by the determinant of the Jacobian mapping
2561 for (unsigned i = 0; i < 3; i++)
2562 {
2563 d_dpsidx_dX(p, q, j, i) *= inv_det_jac;
2564 }
2565 }
2566 }
2567 }
2568 }
2569
2570 //=======================================================================
2571 /// Default value for the number of values at a node
2572 //=======================================================================
2573 const unsigned FiniteElement::Default_Initial_Nvalue = 0;
2574
2575 //======================================================================
2576 /// Default value that is used for the tolerance required when
2577 /// locating nodes via local coordinates
2578 const double FiniteElement::Node_location_tolerance = 1.0e-14;
2579
2580 //=======================================================================
2581 /// Set the default tolerance for a singular jacobian
2582 //=======================================================================
2584
2585 //======================================================================
2586 /// Set the default value of the Accept_negative_jacobian flag to be
2587 /// false
2588 //======================================================================
2590
2591
2592 //======================================================================
2593 /// Set default for static boolean to suppress output while checking
2594 /// for inverted elements
2595 //======================================================================
2597 false;
2598
2599 //========================================================================
2600 /// Static array that holds the number of rows in the second derivative
2601 /// matrix as a function of spatial dimension. In one-dimension, there is
2602 /// only one possible second derivative. In two-dimensions, there are three,
2603 /// the two second derivatives and the mixed derivatives. In three
2604 /// dimensions there are six.
2605 //=========================================================================
2606 const unsigned FiniteElement::N2deriv[4] = {0, 1, 3, 6};
2607
2608 //==========================================================================
2609 /// Calculate the mapping from local to eulerian coordinates
2610 /// assuming that the coordinates are aligned in the direction of the local
2611 /// coordinates, i.e. there are no cross terms and the jacobian is diagonal.
2612 /// The local derivatives are passed as dpsids and the jacobian and
2613 /// inverse jacobian are returned.
2614 //==========================================================================
2616 const DShape& dpsids,
2617 DenseMatrix<double>& jacobian,
2619 {
2620 // Find the dimension of the element
2621 const unsigned el_dim = dim();
2622 // Find the number of shape functions and shape functions types
2623 // Equal to the number of nodes and their position types by definition
2624 const unsigned n_shape = nnode();
2625 const unsigned n_shape_type = nnodal_position_type();
2626
2627#ifdef PARANOID
2628 // Check for dimension compatibility
2630 {
2631 std::ostringstream error_message;
2632 error_message << "Dimension mismatch" << std::endl;
2633 error_message << "The elemental dimension: " << Elemental_dimension
2634 << " must equal the nodal dimension: " << Nodal_dimension
2635 << " for the jacobian of the mapping to be well-defined"
2636 << std::endl;
2637 throw OomphLibError(
2638 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
2639 }
2640#endif
2641
2642 // In this case we assume that there are no cross terms, that is
2643 // global coordinate 0 is always in the direction of local coordinate 0
2644
2645 // Loop over the coordinates
2646 for (unsigned i = 0; i < el_dim; i++)
2647 {
2648 // Zero the jacobian and inverse jacobian entries
2649 for (unsigned j = 0; j < el_dim; j++)
2650 {
2651 jacobian(i, j) = 0.0;
2652 inverse_jacobian(i, j) = 0.0;
2653 }
2654
2655 // Loop over the shape functions
2656 for (unsigned l = 0; l < n_shape; l++)
2657 {
2658 // Loop over the types of dof
2659 for (unsigned k = 0; k < n_shape_type; k++)
2660 {
2661 // Derivatives are always dx_{i}/ds_{i}
2662 jacobian(i, i) += raw_nodal_position_gen(l, k, i) * dpsids(l, k, i);
2663 }
2664 }
2665 }
2666
2667 // Now calculate the determinant of the matrix
2668 double det = 1.0;
2669 for (unsigned i = 0; i < el_dim; i++)
2670 {
2671 det *= jacobian(i, i);
2672 }
2673
2674// Report if Matrix is singular, or negative
2675#ifdef PARANOID
2677#endif
2678
2679 // Calculate the inverse mapping (trivial in this case)
2680 for (unsigned i = 0; i < el_dim; i++)
2681 {
2682 inverse_jacobian(i, i) = 1.0 / jacobian(i, i);
2683 }
2684
2685 // Return the value of the Jacobian
2686 return (det);
2687 }
2688
2689 //========================================================================
2690 /// Template-free interface calculating the derivative of the jacobian
2691 /// of a mapping with respect to the nodal coordinates X_ij. This is
2692 /// slightly inefficient, given that it uses a switch statement. It can
2693 /// always be overloaded in specific geometric elements, for efficiency
2694 /// reasons.
2695 //========================================================================
2697 const DenseMatrix<double>& jacobian,
2698 const DShape& dpsids,
2700 {
2701 // Determine the spatial dimension of the element
2702 const unsigned el_dim = dim();
2703
2704#ifdef PARANOID
2705 // Determine the number of nodes in the element
2706 const unsigned n_node = nnode();
2707
2708 // Check that djacobian_dX has the correct number of rows (= el_dim)
2709 if (djacobian_dX.nrow() != el_dim)
2710 {
2711 std::ostringstream error_message;
2712 error_message << "djacobian_dX must have the same number of rows as the"
2713 << "\nspatial dimension of the element.";
2714 throw OomphLibError(
2715 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
2716 }
2717 // Check that djacobian_dX has the correct number of columns (= n_node)
2718 if (djacobian_dX.ncol() != n_node)
2719 {
2720 std::ostringstream error_message;
2721 error_message
2722 << "djacobian_dX must have the same number of columns as the"
2723 << "\nnumber of nodes in the element.";
2724 throw OomphLibError(
2725 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
2726 }
2727#endif
2728
2729 // Call the appropriate templated function, depending on the
2730 // element dimension
2731 switch (el_dim)
2732 {
2733 case 0:
2735 jacobian, dpsids, djacobian_dX);
2736 break;
2737 case 1:
2739 jacobian, dpsids, djacobian_dX);
2740 break;
2741 case 2:
2743 jacobian, dpsids, djacobian_dX);
2744 break;
2745 case 3:
2747 jacobian, dpsids, djacobian_dX);
2748 break;
2749 // Catch-all default case: issue warning and die
2750 default:
2751 std::ostringstream error_stream;
2752 error_stream << "Dimension of the element must be 0,1,2 or 3, not "
2753 << el_dim << std::endl;
2754
2755 throw OomphLibError(
2757 }
2758 }
2759
2760 //========================================================================
2761 /// Template-free interface calculating the derivative w.r.t. the nodal
2762 /// coordinates \f$ X_{pq} \f$ of the derivative of the shape functions
2763 /// \f$ \psi_j \f$ w.r.t. the global eulerian coordinates \f$ x_i \f$.
2764 /// I.e. this function calculates
2765 /// \f[ \frac{\partial}{\partial X_{pq}} \left( \frac{\partial \psi_j}{\partial x_i} \right). \f]
2766 /// To do this it requires the determinant of the jacobian mapping, its
2767 /// derivative w.r.t. the nodal coordinates \f$ X_{pq} \f$, the inverse
2768 /// jacobian and the derivatives of the shape functions w.r.t. the local
2769 /// coordinates. The result is returned as a tensor of rank four.
2770 /// Numbering:
2771 /// d_dpsidx_dX(p,q,j,i) = \f$ \frac{\partial}{\partial X_{pq}} \left( \frac{\partial \psi_j}{\partial x_i} \right) \f$
2772 /// This function is slightly inefficient, given that it uses a switch
2773 /// statement. It can always be overloaded in specific geometric elements,
2774 /// for efficiency reasons.
2775 //========================================================================
2777 const double& det_jacobian,
2778 const DenseMatrix<double>& jacobian,
2781 const DShape& dpsids,
2783 {
2784 // Determine the spatial dimension of the element
2785 const unsigned el_dim = dim();
2786
2787#ifdef PARANOID
2788 // Determine the number of nodes in the element
2789 const unsigned n_node = nnode();
2790
2791 // Check that d_dpsidx_dX is of the correct size
2792 if (d_dpsidx_dX.nindex1() != el_dim || d_dpsidx_dX.nindex2() != n_node ||
2793 d_dpsidx_dX.nindex3() != n_node || d_dpsidx_dX.nindex4() != el_dim)
2794 {
2795 std::ostringstream error_message;
2796 error_message << "d_dpsidx_dX must be of the following dimensions:"
2797 << "\nd_dpsidx_dX(el_dim,n_node,n_node,el_dim)";
2798 throw OomphLibError(
2799 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
2800 }
2801#endif
2802
2803 // Call the appropriate templated function, depending on the
2804 // element dimension
2805 switch (el_dim)
2806 {
2807 case 0:
2810 jacobian,
2813 dpsids,
2814 d_dpsidx_dX);
2815 break;
2816 case 1:
2819 jacobian,
2822 dpsids,
2823 d_dpsidx_dX);
2824 break;
2825 case 2:
2828 jacobian,
2831 dpsids,
2832 d_dpsidx_dX);
2833 break;
2834 case 3:
2837 jacobian,
2840 dpsids,
2841 d_dpsidx_dX);
2842 break;
2843 // Catch-all default case: issue warning and die
2844 default:
2845 std::ostringstream error_stream;
2846 error_stream << "Dimension of the element must be 0,1,2 or 3, not "
2847 << el_dim << std::endl;
2848
2849 throw OomphLibError(
2851 }
2852 }
2853
2854 //=====================================================================
2855 /// Convert derivatives w.r.t local coordinates to derivatives w.r.t the
2856 /// coordinates used to assemble the inverse jacobian mapping passed as
2857 /// inverse_jacobian. The derivatives passed in dbasis will be
2858 /// modified in this function from dbasisds to dbasisdX.
2859 //======================================================================
2862 {
2863 // Find the number of basis functions and basis function types
2864 const unsigned n_basis = dbasis.nindex1();
2865 const unsigned n_basis_type = dbasis.nindex2();
2866 // Find the dimension of the array (Must be the elemental dimension)
2867 const unsigned n_dim = dim();
2868
2869 // Allocate temporary (stack) storage of the dimension of the element
2870 double new_derivatives[n_dim];
2871
2872 // Loop over the number of basis functions
2873 for (unsigned l = 0; l < n_basis; l++)
2874 {
2875 // Loop over type of basis functions
2876 for (unsigned k = 0; k < n_basis_type; k++)
2877 {
2878 // Loop over the coordinates
2879 for (unsigned j = 0; j < n_dim; j++)
2880 {
2881 // Zero the new transformed derivatives
2882 new_derivatives[j] = 0.0;
2883 // Do premultiplication by inverse jacobian
2884 for (unsigned i = 0; i < n_dim; i++)
2885 {
2887 }
2888 }
2889 // We now copy the new derivatives into the shape functions
2890 for (unsigned j = 0; j < n_dim; j++)
2891 {
2892 dbasis(l, k, j) = new_derivatives[j];
2893 }
2894 }
2895 }
2896 }
2897
2898 //=====================================================================
2899 /// Convert derivatives w.r.t local coordinates to derivatives w.r.t the
2900 /// coordinates used to assemble the inverse jacobian mapping passed as
2901 /// inverse_jacobian, assuming that the mapping is diagonal. This merely
2902 /// saves a few loops, but is probably worth it.
2903 //======================================================================
2906 {
2907 // Find the number of basis functions and basis function types
2908 const unsigned n_basis = dbasis.nindex1();
2909 const unsigned n_basis_type = dbasis.nindex2();
2910 // Find the dimension of the array (must be the elemental dimension)
2911 const unsigned n_dim = dim();
2912
2913 // Loop over the number of basis functions
2914 for (unsigned l = 0; l < n_basis; l++)
2915 {
2916 // Loop over type of basis functions
2917 for (unsigned k = 0; k < n_basis_type; k++)
2918 {
2919 // Loop over the coordinates
2920 for (unsigned j = 0; j < n_dim; j++)
2921 {
2922 dbasis(l, k, j) *= inverse_jacobian(j, j);
2923 }
2924 }
2925 }
2926 }
2927
2928 //=======================================================================
2929 /// Convert derivatives and second derivatives w.r.t local coordinates to
2930 /// derivatives w.r.t. the coordinates used to assemble the jacobian,
2931 /// inverse_jacobian and jacobian 2 passed. This must be specialised
2932 /// for each dimension, otherwise it gets very ugly
2933 /// Specialisation to one dimension.
2934 //=======================================================================
2935 template<>
2936 void FiniteElement::transform_second_derivatives_template<1>(
2937 const DenseMatrix<double>& jacobian,
2940 DShape& dbasis,
2941 DShape& d2basis) const
2942 {
2943 // Find the number of basis functions and basis function types
2944 const unsigned n_basis = dbasis.nindex1();
2945 const unsigned n_basis_type = dbasis.nindex2();
2946
2947 // The second derivatives are easy, because there can be no mixed terms
2948 // Loop over number of basis functions
2949 for (unsigned l = 0; l < n_basis; l++)
2950 {
2951 // Loop over number of basis function types
2952 for (unsigned k = 0; k < n_basis_type; k++)
2953 {
2954 d2basis(l, k, 0) =
2955 d2basis(l, k, 0) / (jacobian(0, 0) * jacobian(0, 0))
2956 // Second term comes from taking d/dx of (dpsi/ds / dx/ds)
2957 - dbasis(l, k, 0) * jacobian2(0, 0) /
2958 (jacobian(0, 0) * jacobian(0, 0) * jacobian(0, 0));
2959 }
2960 }
2961
2962 // Assemble the first derivatives (do this last so that we don't
2963 // overwrite the dphids before we use it in the above)
2965 }
2966
2967 //=======================================================================
2968 /// Convert derivatives and second derivatives w.r.t local coordinates to
2969 /// derivatives w.r.t. the coordinates used to assemble the jacobian,
2970 /// inverse_jacobian and jacobian 2 passed. This must be specialised
2971 /// for each dimension, otherwise it gets very ugly.
2972 /// Specialisation to two spatial dimensions
2973 //=======================================================================
2974 template<>
2975 void FiniteElement::transform_second_derivatives_template<2>(
2976 const DenseMatrix<double>& jacobian,
2979 DShape& dbasis,
2980 DShape& d2basis) const
2981 {
2982 // Find the number of basis functions and basis function types
2983 const unsigned n_basis = dbasis.nindex1();
2984 const unsigned n_basis_type = dbasis.nindex2();
2985
2986 // Calculate the determinant
2987 const double det =
2988 jacobian(0, 0) * jacobian(1, 1) - jacobian(0, 1) * jacobian(1, 0);
2989
2990 // Second derivatives ... the approach taken here is to construct
2991 // dphidX/ds which can then be used to calculate the second derivatives
2992 // using the relationship d/dX = inverse_jacobian*d/ds
2993
2994 double ddetds[2];
2995
2996 ddetds[0] =
2997 jacobian2(0, 0) * jacobian(1, 1) + jacobian(0, 0) * jacobian2(2, 1) -
2998 jacobian2(0, 1) * jacobian(1, 0) - jacobian(0, 1) * jacobian2(2, 0);
2999 ddetds[1] =
3000 jacobian2(2, 0) * jacobian(1, 1) + jacobian(0, 0) * jacobian2(1, 1) -
3001 jacobian2(2, 1) * jacobian(1, 0) - jacobian(0, 1) * jacobian2(1, 0);
3002
3003 // Calculate the derivatives of the inverse jacobian wrt the local
3004 // coordinates
3005 double dinverse_jacobiands[2][2][2];
3006
3007 dinverse_jacobiands[0][0][0] =
3008 jacobian2(2, 1) / det - jacobian(1, 1) * ddetds[0] / (det * det);
3009 dinverse_jacobiands[0][1][0] =
3010 -jacobian2(0, 1) / det + jacobian(0, 1) * ddetds[0] / (det * det);
3011 dinverse_jacobiands[1][0][0] =
3012 -jacobian2(2, 0) / det + jacobian(1, 0) * ddetds[0] / (det * det);
3013 dinverse_jacobiands[1][1][0] =
3014 jacobian2(0, 0) / det - jacobian(0, 0) * ddetds[0] / (det * det);
3015
3016 dinverse_jacobiands[0][0][1] =
3017 jacobian2(1, 1) / det - jacobian(1, 1) * ddetds[1] / (det * det);
3018 dinverse_jacobiands[0][1][1] =
3019 -jacobian2(2, 1) / det + jacobian(0, 1) * ddetds[1] / (det * det);
3020 dinverse_jacobiands[1][0][1] =
3021 -jacobian2(1, 0) / det + jacobian(1, 0) * ddetds[1] / (det * det);
3022 dinverse_jacobiands[1][1][1] =
3023 jacobian2(2, 0) / det - jacobian(0, 0) * ddetds[1] / (det * det);
3024
3025 // Set up derivatives of dpsidx wrt local coordinates
3028
3029 for (unsigned l = 0; l < n_basis; l++)
3030 {
3031 for (unsigned k = 0; k < n_basis_type; k++)
3032 {
3033 for (unsigned j = 0; j < 2; j++)
3034 {
3035 // Note that we can't have an inner loop because of the
3036 // convention I've chosen for the mixed derivatives!
3037 dphidXds0(l, k, j) = dinverse_jacobiands[j][0][0] * dbasis(l, k, 0) +
3038 dinverse_jacobiands[j][1][0] * dbasis(l, k, 1) +
3039 inverse_jacobian(j, 0) * d2basis(l, k, 0) +
3040 inverse_jacobian(j, 1) * d2basis(l, k, 2);
3041
3042 dphidXds1(l, k, j) = dinverse_jacobiands[j][0][1] * dbasis(l, k, 0) +
3043 dinverse_jacobiands[j][1][1] * dbasis(l, k, 1) +
3044 inverse_jacobian(j, 0) * d2basis(l, k, 2) +
3045 inverse_jacobian(j, 1) * d2basis(l, k, 1);
3046 }
3047 }
3048 }
3049
3050 // Now calculate the DShape d2phidX
3051 for (unsigned l = 0; l < n_basis; l++)
3052 {
3053 for (unsigned k = 0; k < n_basis_type; k++)
3054 {
3055 // Zero dpsidx
3056 for (unsigned j = 0; j < 3; j++)
3057 {
3058 d2basis(l, k, j) = 0.0;
3059 }
3060
3061 // Do premultiplication by inverse jacobian
3062 for (unsigned i = 0; i < 2; i++)
3063 {
3064 d2basis(l, k, i) = inverse_jacobian(i, 0) * dphidXds0(l, k, i) +
3065 inverse_jacobian(i, 1) * dphidXds1(l, k, i);
3066 }
3067 // Calculate mixed derivative term
3068 d2basis(l, k, 2) += inverse_jacobian(0, 0) * dphidXds0(l, k, 1) +
3069 inverse_jacobian(0, 1) * dphidXds1(l, k, 1);
3070 }
3071 }
3072
3073 // Assemble the first derivatives second, so that we don't
3074 // overwrite dphids
3076 }
3077
3078
3079 //=======================================================================
3080 /// Convert derivatives and second derivatives w.r.t local coordinates to
3081 /// derivatives w.r.t. the coordinates used to assemble the jacobian,
3082 /// inverse_jacobian and jacobian 2 passed. This must be specialised
3083 /// for each dimension, otherwise it gets very ugly
3084 /// Specialisation to one dimension.
3085 //=======================================================================
3086 template<>
3087 void FiniteElement::transform_second_derivatives_diagonal<1>(
3088 const DenseMatrix<double>& jacobian,
3091 DShape& dbasis,
3092 DShape& d2basis) const
3093 {
3094 FiniteElement::transform_second_derivatives_template<1>(
3096 }
3097
3098
3099 //=========================================================================
3100 /// Convert second derivatives w.r.t. local coordinates to
3101 /// second derivatives w.r.t. the coordinates passed in the tensor
3102 /// coordinate. Specialised to two spatial dimension
3103 //=========================================================================
3104 template<>
3105 void FiniteElement::transform_second_derivatives_diagonal<2>(
3106 const DenseMatrix<double>& jacobian,
3109 DShape& dbasis,
3110 DShape& d2basis) const
3111 {
3112 // Find the number of basis functions and basis function types
3113 const unsigned n_basis = dbasis.nindex1();
3114 const unsigned n_basis_type = dbasis.nindex2();
3115
3116 // Again we assume that there are no cross terms and that coordinate
3117 // i depends only upon local coordinate i
3118
3119 // Now calculate the DShape d2phidx
3120 for (unsigned l = 0; l < n_basis; l++)
3121 {
3122 for (unsigned k = 0; k < n_basis_type; k++)
3123 {
3124 // Second derivatives
3125 d2basis(l, k, 0) =
3126 d2basis(l, k, 0) / (jacobian(0, 0) * jacobian(0, 0)) -
3127 dbasis(l, k, 0) * jacobian2(0, 0) /
3128 (jacobian(0, 0) * jacobian(0, 0) * jacobian(0, 0));
3129
3130 d2basis(l, k, 1) =
3131 d2basis(l, k, 1) / (jacobian(1, 1) * jacobian(1, 1)) -
3132 dbasis(l, k, 1) * jacobian2(1, 1) /
3133 (jacobian(1, 1) * jacobian(1, 1) * jacobian(1, 1));
3134
3135 d2basis(l, k, 2) = d2basis(l, k, 2) / (jacobian(0, 0) * jacobian(1, 1));
3136 }
3137 }
3138
3139
3140 // Assemble the first derivatives
3142 }
3143
3144
3145 //=============================================================================
3146 /// Convert derivatives and second derivatives w.r.t. local coordiantes
3147 /// to derivatives and second derivatives w.r.t. the coordinates used to
3148 /// assemble the jacobian, inverse jacobian and jacobian2 passed to the
3149 /// function. This is a template-free general interface, that should be
3150 /// overloaded for efficiency
3151 //============================================================================
3153 const DenseMatrix<double>& jacobian,
3156 DShape& dbasis,
3157 DShape& d2basis) const
3158 {
3159 // Find the dimension of the element
3160 const unsigned el_dim = dim();
3161 // Choose the appropriate function based on the dimension of the element
3162 switch (el_dim)
3163 {
3164 case 1:
3167 break;
3168 case 2:
3171 break;
3172
3173 case 3:
3174 throw OomphLibError("Not implemented yet ... maybe one day",
3177
3178 // transform_second_derivatives_template<3>(dphids,d2phids,jacobian,
3179 // inverse_jacobian,jacobian2,
3180 // dphidX,d2phidX);
3181 break;
3182 // Catch-all default case: issue warning and die
3183 default:
3184 std::ostringstream error_stream;
3185 error_stream << "Dimension of the element must be 1,2 or 3, not "
3186 << el_dim << std::endl;
3187
3188 throw OomphLibError(
3190 }
3191 }
3192
3193
3194 //======================================================================
3195 /// The destructor cleans up the memory allocated
3196 /// for storage of pointers to nodes. Internal and external data get
3197 /// wiped by the GeneralisedElement destructor; nodes get
3198 /// killed in mesh destructor.
3199 //=======================================================================
3201 {
3202 // Delete the storage allocated for the pointers to the loca nodes
3203 delete[] Node_pt;
3204
3205 // Delete the storage allocated for the nodal numbering schemes
3206 if (Nodal_local_eqn)
3207 {
3208 delete[] Nodal_local_eqn[0];
3209 delete[] Nodal_local_eqn;
3210 }
3211 }
3212
3213
3214 //==============================================================
3215 /// Get the local fraction of the node j in the element;
3216 /// vector sets its own size
3217 //==============================================================
3220 {
3221 // Default implementation is rather dumb
3222 // Get the local coordinate and scale by local coordinate range
3224 unsigned n_coordinates = s_fraction.size();
3225 for (unsigned i = 0; i < n_coordinates; i++)
3226 {
3227 s_fraction[i] = (s_fraction[i] - s_min()) / (s_max() - s_min());
3228 }
3229 }
3230
3231 //=======================================================================
3232 /// Set the spatial integration scheme and also calculate the values of the
3233 /// shape functions and their derivatives w.r.t. the local coordinates,
3234 /// placing the values into storage so that they may be re-used,
3235 /// without recalculation
3236 //=======================================================================
3238 {
3239 // Assign the integration scheme
3241 }
3242
3243 //=========================================================================
3244 /// Return the shape function stored at the ipt-th integration
3245 /// point.
3246 //=========================================================================
3247 void FiniteElement::shape_at_knot(const unsigned& ipt, Shape& psi) const
3248 {
3249 // Find the dimension of the element
3250 const unsigned el_dim = dim();
3251 // Storage for the local coordinates of the integration point
3253 // Set the local coordinate
3254 for (unsigned i = 0; i < el_dim; i++)
3255 {
3256 s[i] = integral_pt()->knot(ipt, i);
3257 }
3258 // Get the shape function
3259 shape(s, psi);
3260 }
3261
3262 //=========================================================================
3263 /// Return the shape function and its derivatives w.r.t. the local
3264 /// coordinates at the ipt-th integration point.
3265 //=========================================================================
3267 Shape& psi,
3268 DShape& dpsids) const
3269 {
3270 // Find the dimension of the element
3271 const unsigned el_dim = dim();
3272 // Storage for the local coordinates of the integration point
3274 // Set the local coordinate
3275 for (unsigned i = 0; i < el_dim; i++)
3276 {
3277 s[i] = integral_pt()->knot(ipt, i);
3278 }
3279 // Get the shape function and derivatives
3281 }
3282
3283 //=========================================================================
3284 /// Calculate the shape function and its first and second derivatives
3285 /// w.r.t. local coordinates at the ipt-th integration point.
3286 /// Numbering:
3287 /// \b 1D:
3288 /// d2psids(i,0) = \f$ d^2 \psi_j / d s^2 \f$
3289 /// \b 2D:
3290 /// d2psids(i,0) = \f$ \partial^2 \psi_j / \partial s_0^2 \f$
3291 /// d2psids(i,1) = \f$ \partial^2 \psi_j / \partial s_1^2 \f$
3292 /// d2psids(i,2) = \f$ \partial^2 \psi_j / \partial s_0 \partial s_1 \f$
3293 /// \b 3D:
3294 /// d2psids(i,0) = \f$ \partial^2 \psi_j / \partial s_0^2 \f$
3295 /// d2psids(i,1) = \f$ \partial^2 \psi_j / \partial s_1^2 \f$
3296 /// d2psids(i,2) = \f$ \partial^2 \psi_j / \partial s_2^2 \f$
3297 /// d2psids(i,3) = \f$ \partial^2 \psi_j / \partial s_0 \partial s_1 \f$
3298 /// d2psids(i,4) = \f$ \partial^2 \psi_j / \partial s_0 \partial s_2 \f$
3299 /// d2psids(i,5) = \f$ \partial^2 \psi_j / \partial s_1 \partial s_2 \f$
3300 //=========================================================================
3302 Shape& psi,
3303 DShape& dpsids,
3304 DShape& d2psids) const
3305 {
3306 // Find the dimension of the element
3307 const unsigned el_dim = dim();
3308 // Storage for the local coordinates of the integration point
3310 // Set the local coordinate
3311 for (unsigned i = 0; i < el_dim; i++)
3312 {
3313 s[i] = integral_pt()->knot(ipt, i);
3314 }
3315 // Get the shape function and first and second derivatives
3317 }
3318
3319 //=========================================================================
3320 /// Compute the geometric shape functions and also
3321 /// first derivatives w.r.t. global coordinates at local coordinate s;
3322 /// Returns Jacobian of mapping from global to local coordinates.
3323 /// Most general form of the function, but may be over-loaded, if desired
3324 //=========================================================================
3326 Shape& psi,
3327 DShape& dpsi) const
3328 {
3329 // Find the element dimension
3330 const unsigned el_dim = dim();
3331
3332 // Get the values of the shape functions and their local derivatives
3333 // Temporarily stored in dpsi
3335
3336 // Allocate memory for the inverse jacobian
3338 // Now calculate the inverse jacobian
3340
3341 // Now set the values of the derivatives to be dpsidx
3343 // Return the determinant of the jacobian
3344 return det;
3345 }
3346
3347 //========================================================================
3348 /// Compute the geometric shape functions and also first
3349 /// derivatives w.r.t. global coordinates at integration point ipt.
3350 /// Most general form of function, but may be over-loaded if desired
3351 //========================================================================
3353 Shape& psi,
3354 DShape& dpsi) const
3355 {
3356 // Find the element dimension
3357 const unsigned el_dim = dim();
3358
3359 // Get the values of the shape function and local derivatives
3360 // Temporarily store it in dpsi
3362
3363 // Allocate memory for the inverse jacobian
3365 // Now calculate the inverse jacobian
3367
3368 // Now set the values of the derivatives to dpsidx
3370 // Return the determinant of the jacobian
3371 return det;
3372 }
3373
3374
3375 //========================================================================
3376 /// Compute the geometric shape functions (psi) at integration point
3377 /// ipt. Return the determinant of the jacobian of the mapping (detJ).
3378 /// Additionally calculate the derivatives of "detJ" w.r.t. the
3379 /// nodal coordinates.
3380 //========================================================================
3382 const unsigned& ipt, Shape& psi, DenseMatrix<double>& djacobian_dX) const
3383 {
3384 // Find the element dimension
3385 const unsigned el_dim = dim();
3386
3387 // Get the values of the shape function and local derivatives
3388 unsigned nnod = nnode();
3391
3392 // Allocate memory for the jacobian and the inverse of the jacobian
3394
3395 // Now calculate the inverse jacobian
3396 const double det =
3398
3399 // Calculate the derivative of the jacobian w.r.t. nodal coordinates
3400 // Note: must call this before "transform_derivatives(...)" since this
3401 // function requires dpsids rather than dpsidx
3403
3404 // Return the determinant of the jacobian
3405 return det;
3406 }
3407
3408
3409 //========================================================================
3410 /// Compute the geometric shape functions (psi) and first
3411 /// derivatives w.r.t. global coordinates (dpsidx) at integration point
3412 /// ipt. Return the determinant of the jacobian of the mapping (detJ).
3413 /// Additionally calculate the derivatives of both "detJ" and "dpsidx"
3414 /// w.r.t. the nodal coordinates.
3415 /// Most general form of function, but may be over-loaded if desired.
3416 //========================================================================
3418 const unsigned& ipt,
3419 Shape& psi,
3420 DShape& dpsi,
3423 {
3424 // Find the element dimension
3425 const unsigned el_dim = dim();
3426
3427 // Get the values of the shape function and local derivatives
3428 // Temporarily store in dpsi
3430
3431 // Allocate memory for the jacobian and the inverse of the jacobian
3433
3434 // Now calculate the inverse jacobian
3435 const double det =
3437
3438 // Calculate the derivative of the jacobian w.r.t. nodal coordinates
3439 // Note: must call this before "transform_derivatives(...)" since this
3440 // function requires dpsids rather than dpsidx
3442
3443 // Calculate the derivative of dpsidx w.r.t. nodal coordinates
3444 // Note: this function also requires dpsids rather than dpsidx
3447
3448 // Now set the values of the derivatives to dpsidx
3450
3451 // Return the determinant of the jacobian
3452 return det;
3453 }
3454
3455
3456 //===========================================================================
3457 /// Compute the geometric shape functions and also first
3458 /// and second derivatives w.r.t. global coordinates at local coordinate s;
3459 /// Also returns Jacobian of mapping from global to local coordinates.
3460 /// Numbering:
3461 /// \b 1D:
3462 /// d2psidx(i,0) = \f$ d^2 \psi_j / d x^2 \f$
3463 /// \b 2D:
3464 /// d2psidx(i,0) = \f$ \partial^2 \psi_j / \partial x_0^2 \f$
3465 /// d2psidx(i,1) = \f$ \partial^2 \psi_j / \partial x_1^2 \f$
3466 /// d2psidx(i,2) = \f$ \partial^2 \psi_j / \partial x_0 \partial x_1 \f$
3467 /// \b 3D:
3468 /// d2psidx(i,0) = \f$ \partial^2 \psi_j / \partial x_0^2 \f$
3469 /// d2psidx(i,1) = \f$ \partial^2 \psi_j / \partial x_1^2 \f$
3470 /// d2psidx(i,2) = \f$ \partial^2 \psi_j / \partial x_2^2 \f$
3471 /// d2psidx(i,3) = \f$ \partial^2 \psi_j / \partial x_0 \partial x_1 \f$
3472 /// d2psidx(i,4) = \f$ \partial^2 \psi_j / \partial x_0 \partial x_2 \f$
3473 /// d2psidx(i,5) = \f$ \partial^2 \psi_j / \partial x_1 \partial x_2 \f$
3474 //===========================================================================
3476 Shape& psi,
3477 DShape& dpsi,
3478 DShape& d2psi) const
3479 {
3480 // Find the values of the indices of the shape functions
3481 // Locally cached.
3482 // Find the element dimension
3483 const unsigned el_dim = dim();
3484 // Find the number of second derivatives required
3485 const unsigned n_deriv = N2deriv[el_dim];
3486
3487 // Get the values of the shape function and local derivatives
3489
3490 // Allocate memory for the jacobian and inverse jacobian
3492 // Calculate the jacobian and inverse jacobian
3493 const double det =
3495
3496 // Allocate memory for the jacobian of second derivatives
3498 // Assemble the jacobian of second derivatives
3500
3501 // Now set the value of the derivatives
3503 jacobian, inverse_jacobian, jacobian2, dpsi, d2psi);
3504 // Return the determinant of the mapping
3505 return det;
3506 }
3507
3508 //===========================================================================
3509 /// Compute the geometric shape functions and also first
3510 /// and second derivatives w.r.t. global coordinates at ipt-th integration
3511 /// point
3512 /// Returns Jacobian of mapping from global to local coordinates.
3513 /// This is the most general version, may be overloaded, if desired.
3514 /// Numbering:
3515 /// \b 1D:
3516 /// d2psidx(i,0) = \f$ d^2 \psi_j / d x^2 \f$
3517 /// \b 2D:
3518 /// d2psidx(i,0) = \f$ \partial^2 \psi_j / \partial x_0^2 \f$
3519 /// d2psidx(i,1) = \f$ \partial^2 \psi_j / \partial x_1^2 \f$
3520 /// d2psidx(i,2) = \f$ \partial^2 \psi_j / \partial x_0 \partial x_1 \f$
3521 /// \b 3D:
3522 /// d2psidx(i,0) = \f$ \partial^2 \psi_j / \partial x_0^2 \f$
3523 /// d2psidx(i,1) = \f$ \partial^2 \psi_j / \partial x_1^2 \f$
3524 /// d2psidx(i,2) = \f$ \partial^2 \psi_j / \partial x_2^2 \f$
3525 /// d2psidx(i,3) = \f$ \partial^2 \psi_j / \partial x_0 \partial x_1 \f$
3526 /// d2psidx(i,4) = \f$ \partial^2 \psi_j / \partial x_0 \partial x_2 \f$
3527 /// d2psidx(i,5) = \f$ \partial^2 \psi_j / \partial x_1 \partial x_2 \f$
3528 //==========================================================================
3530 Shape& psi,
3531 DShape& dpsi,
3532 DShape& d2psi) const
3533 {
3534 // Find the values of the indices of the shape functions
3535 // Locally cached
3536 // Find the element dimension
3537 const unsigned el_dim = dim();
3538 // Find the number of second derivatives required
3539 const unsigned n_deriv = N2deriv[el_dim];
3540
3541 // Get the values of the shape function and local derivatives
3543
3544 // Allocate memory for the jacobian and inverse jacobian
3546 // Calculate the jacobian and inverse jacobian
3547 const double det =
3549
3550 // Allocate memory for the jacobian of second derivatives
3552 // Assemble the jacobian of second derivatives
3554
3555 // Now set the value of the derivatives
3557 jacobian, inverse_jacobian, jacobian2, dpsi, d2psi);
3558 // Return the determinant of the mapping
3559 return det;
3560 }
3561
3562
3563 //==========================================================================
3564 /// This function loops over the nodal data of the element, adds the
3565 /// GLOBAL equation numbers to the local-to-global look-up scheme and
3566 /// fills in the Nodal_local_eqn look-up scheme for the local equation
3567 /// numbers
3568 /// If the boolean argument is true then pointers to the dofs will be
3569 /// stored in Dof_pt
3570 //==========================================================================
3572 const bool& store_local_dof_pt)
3573 {
3574 // Find the number of nodes
3575 const unsigned n_node = nnode();
3576 // If there are nodes
3577 if (n_node > 0)
3578 {
3579 // Find the number of local equations assigned so far
3580 unsigned local_eqn_number = ndof();
3581
3582 // We need to find the total number of values stored at the node
3583 // Initialise to the number of values stored at the first node
3584 unsigned n_total_values = node_pt(0)->nvalue();
3585 // Loop over the other nodes and add the values stored
3586 for (unsigned n = 1; n < n_node; n++)
3587 {
3589 }
3590
3591 // If allocated delete the old storage
3592 if (Nodal_local_eqn)
3593 {
3594 delete[] Nodal_local_eqn[0];
3595 delete[] Nodal_local_eqn;
3596 }
3597
3598 // If there are no values, we are done, null out the storage and
3599 // return
3600 if (n_total_values == 0)
3601 {
3602 Nodal_local_eqn = 0;
3603 return;
3604 }
3605
3606 // Resize the storage for the nodal local equation numbers
3607 // Firstly allocate pointers to rows for each node
3608 Nodal_local_eqn = new int*[n_node];
3609 // Now allocate storage for the equation numbers
3610 Nodal_local_eqn[0] = new int[n_total_values];
3611 // initially all local equations are unclassified
3612 for (unsigned i = 0; i < n_total_values; i++)
3613 {
3615 }
3616
3617 // Loop over the remaining rows and set their pointers
3618 for (unsigned n = 1; n < n_node; ++n)
3619 {
3620 // Initially set the pointer to the i-th row to the pointer
3621 // to the i-1th row
3623 // Now increase the row pointer by the number of values
3624 // stored at the i-1th node
3625 Nodal_local_eqn[n] += Node_pt[n - 1]->nvalue();
3626 }
3627
3628
3629 // A local queue to store the global equation numbers
3630 std::deque<unsigned long> global_eqn_number_queue;
3631
3632 // Now loop over the nodes again and assign local equation numbers
3633 for (unsigned n = 0; n < n_node; n++)
3634 {
3635 // Pointer to node
3636 Node* const nod_pt = node_pt(n);
3637
3638 // Find the number of values stored at the node
3639 unsigned n_value = nod_pt->nvalue();
3640
3641 // Loop over the number of values
3642 for (unsigned j = 0; j < n_value; j++)
3643 {
3644 // Get the GLOBAL equation number
3645 long eqn_number = nod_pt->eqn_number(j);
3646 // If the GLOBAL equation number is positive (a free variable)
3647 if (eqn_number >= 0)
3648 {
3649 // Add the GLOBAL equation number to the queue
3651 // Add pointer to the dof to the queue if required
3653 {
3654 GeneralisedElement::Dof_pt_deque.push_back(nod_pt->value_pt(j));
3655 }
3656 // Add the local equation number to the local scheme
3658 // Increase the local number
3660 }
3661 else
3662 {
3663 // Set the local scheme to be pinned
3665 }
3666 }
3667 }
3668
3669 // Now add our global equations numbers to the internal element storage
3672 // Clear the memory used in the deque
3674 {
3675 std::deque<double*>().swap(GeneralisedElement::Dof_pt_deque);
3676 }
3677 }
3678 }
3679
3680
3681 //============================================================================
3682 /// This function calculates the entries of Jacobian matrix, used in
3683 /// the Newton method, associated with the nodal degrees of freedom.
3684 /// It does this using finite differences,
3685 /// rather than an analytical formulation, so can be done in total generality.
3686 //==========================================================================
3689 {
3690 // Find the number of nodes
3691 const unsigned n_node = nnode();
3692 // If there aren't any nodes, then return straight awayy
3693 if (n_node == 0)
3694 {
3695 return;
3696 }
3697
3698 // Call the update function to ensure that the element is in
3699 // a consistent state before finite differencing starts
3701
3702 // Find the number of dofs in the element
3703 const unsigned n_dof = ndof();
3704 // Create newres vector
3706
3707 // Integer storage for local unknown
3708 int local_unknown = 0;
3709
3710 // Use the default finite difference step
3711 const double fd_step = Default_fd_jacobian_step;
3712
3713 // Loop over the nodes
3714 for (unsigned n = 0; n < n_node; n++)
3715 {
3716 // Get the number of values stored at the node
3717 const unsigned n_value = node_pt(n)->nvalue();
3718
3719 // Loop over the number of values
3720 for (unsigned i = 0; i < n_value; i++)
3721 {
3722 // Get the local equation number
3724 // If it's not pinned
3725 if (local_unknown >= 0)
3726 {
3727 // Store a pointer to the nodal data value
3728 double* const value_pt = node_pt(n)->value_pt(i);
3729
3730 // Save the old value of the Nodal data
3731 const double old_var = *value_pt;
3732
3733 // Increment the value of the Nodal data
3734 *value_pt += fd_step;
3735
3736 // Now update any dependent variables
3738
3739 // Calculate the new residuals
3741
3742 // Do finite differences
3743 for (unsigned m = 0; m < n_dof; m++)
3744 {
3745 double sum = (newres[m] - residuals[m]) / fd_step;
3746 // Stick the entry into the Jacobian matrix
3747 jacobian(m, local_unknown) = sum;
3748 }
3749
3750 // Reset the Nodal data
3751 *value_pt = old_var;
3752
3753 // Reset any dependent variables
3755 }
3756 }
3757 }
3758
3759 // End of finite difference loop
3760 // Final reset of any dependent data
3762 }
3763
3764
3765 //=======================================================================
3766 /// Compute derivatives of elemental residual vector with respect
3767 /// to nodal coordinates. Default implementation by FD can be overwritten
3768 /// for specific elements.
3769 /// dresidual_dnodal_coordinates(l,i,j) = d res(l) / dX_{ij}
3770 /// /=======================================================================
3773 {
3774 // Number of nodes
3775 unsigned n_nod = nnode();
3776
3777 // If the element has no nodes (why??!!) return straightaway
3778 if (n_nod == 0) return;
3779
3780 // Get dimension from first node
3781 unsigned dim_nod = node_pt(0)->ndim();
3782
3783 // Number of dofs
3784 unsigned n_dof = ndof();
3785
3786 // Get reference residual
3790
3791 // FD step
3793
3794 // Do FD loop
3795 for (unsigned j = 0; j < n_nod; j++)
3796 {
3797 // Get node
3798 Node* nod_pt = node_pt(j);
3799
3800 // Loop over coordinate directions
3801 for (unsigned i = 0; i < dim_nod; i++)
3802 {
3803 // Make backup
3804 double backup = nod_pt->x(i);
3805
3806 // Do FD step. No node update required as we're
3807 // attacking the coordinate directly...
3808 nod_pt->x(i) += eps_fd;
3809
3810 // Perform auxiliary node update function
3811 nod_pt->perform_auxiliary_node_update_fct();
3812
3813 // Get advanced residual
3815
3816 // Fill in FD entries [Loop order is "wrong" here as l is the
3817 // slow index but this is in a function that's costly anyway
3818 // and gives us the fastest loop outside where these tensor
3819 // is actually used.]
3820 for (unsigned l = 0; l < n_dof; l++)
3821 {
3823 (res_pls[l] - res[l]) / eps_fd;
3824 }
3825
3826 // Reset coordinate. No node update required as we're
3827 // attacking the coordinate directly...
3828 nod_pt->x(i) = backup;
3829
3830 // Perform auxiliary node update function
3831 nod_pt->perform_auxiliary_node_update_fct();
3832 }
3833 }
3834 }
3835
3836
3837 //===============================================================
3838 /// Return the number of the node located at *node_pt
3839 /// if this node is in the element, else return \f$ -1 \f$
3840 //===============================================================
3842 {
3843 // Initialise the number to -1
3844 int number = -1;
3845 // Find the number of nodes
3846 unsigned n_node = nnode();
3847#ifdef PARANOID
3848 {
3849 // Error check that node does not appear in element more than once
3850 unsigned count = 0;
3851 // Storage for the local node numbers of the element
3852 std::vector<int> local_node_number;
3853 // Loop over the nodes
3854 for (unsigned i = 0; i < n_node; i++)
3855 {
3856 // If the node is present increase the counter
3857 // and store the local node number
3858 if (node_pt(i) == global_node_pt)
3859 {
3860 ++count;
3861 local_node_number.push_back(i);
3862 }
3863 }
3864
3865 // If the node appears more than once, complain
3866 if (count > 1)
3867 {
3868 std::ostringstream error_stream;
3869 error_stream << "Node " << global_node_pt << " appears " << count
3870 << " times in an element." << std::endl
3871 << "In positions: ";
3872 for (std::vector<int>::iterator it = local_node_number.begin();
3873 it != local_node_number.end();
3874 ++it)
3875 {
3876 error_stream << *it << " ";
3877 }
3878 error_stream << std::endl << "That seems very odd." << std::endl;
3879
3880 throw OomphLibError(
3882 }
3883 }
3884#endif
3885
3886 // Loop over the nodes
3887 for (unsigned i = 0; i < n_node; i++)
3888 {
3889 // If the passed node pointer is present in the element
3890 // set number to be its local node number
3891 if (node_pt(i) == global_node_pt)
3892 {
3893 number = i;
3894 break;
3895 }
3896 }
3897
3898 // Return the node number
3899 return number;
3900 }
3901
3902
3903 //==========================================================================
3904 /// If there is a node at the local coordinate, s, return the pointer
3905 /// to the node. If not return 0. Note that this is a default, brute
3906 /// force implementation, can almost certainly be made more efficient for
3907 /// specific elements.
3908 //==========================================================================
3910 const Vector<double>& s) const
3911 {
3912 // Locally cache the tolerance
3913 const double tol = Node_location_tolerance;
3915 // Locally cache the member data
3916 const unsigned el_dim = Elemental_dimension;
3917 const unsigned n_node = Nnode;
3918 // Loop over the nodes
3919 for (unsigned n = 0; n < n_node; n++)
3920 {
3921 bool Match = true;
3922 // Find the local coordinate of the node
3924 for (unsigned i = 0; i < el_dim; i++)
3925 {
3926 // Calculate the difference between coordinates
3927 // and if it's bigger than our tolerance
3928 // break out of the (inner)loop
3929 if (std::fabs(s[i] - s_node[i]) > tol)
3930 {
3931 Match = false;
3932 break;
3933 }
3934 }
3935 // If we haven't complained then we have a match
3936 if (Match)
3937 {
3938 return node_pt(n);
3939 }
3940 }
3941 // If we get here, we have no match
3942 return 0;
3943 }
3944
3945 //======================================================================
3946 /// Compute centre of gravity of all nodes and radius of node that
3947 /// is furthest from it. Used to assess approximately if a point
3948 /// is likely to be contained with an element in locate_zeta-like
3949 /// operations. NOTE: All computed in terms of zeta!
3950 //======================================================================
3952 Vector<double>& cog, double& max_radius) const
3953 {
3954 // Initialise
3955 cog.resize(Elemental_dimension);
3956 max_radius = 0.0;
3957
3958 // Get cog
3959 unsigned nnod = nnode();
3960 for (unsigned j = 0; j < nnod; j++)
3961 {
3962 for (unsigned i = 0; i < Elemental_dimension; i++)
3963 {
3964 cog[i] += zeta_nodal(j, 0, i);
3965 }
3966 }
3967 for (unsigned i = 0; i < Elemental_dimension; i++)
3968 {
3969 cog[i] /= double(nnod);
3970 }
3971
3972 // Get max distance
3973 for (unsigned j = 0; j < nnod; j++)
3974 {
3975 double dist_squared = 0.0;
3976 for (unsigned i = 0; i < Elemental_dimension; i++)
3977 {
3978 dist_squared +=
3979 (cog[i] - zeta_nodal(j, 0, i)) * (cog[i] - zeta_nodal(j, 0, i));
3980 }
3982 }
3984 }
3985
3986 //======================================================================
3987 /// Return FE interpolated coordinate x[i] at local coordinate s
3988 //======================================================================
3990 const unsigned& i) const
3991 {
3992 // Find the number of nodes
3993 const unsigned n_node = nnode();
3994 // Find the number of positional types
3995 const unsigned n_position_type = nnodal_position_type();
3996 // Assign storage for the local shape function
3998 // Find the values of shape function
3999 shape(s, psi);
4000
4001 // Initialise value of x
4002 double interpolated_x = 0.0;
4003 // Loop over the local nodes
4004 for (unsigned l = 0; l < n_node; l++)
4005 {
4006 // Loop over the number of dofs
4007 for (unsigned k = 0; k < n_position_type; k++)
4008 {
4010 }
4011 }
4012
4013 return (interpolated_x);
4014 }
4015
4016 //=========================================================================
4017 /// Return FE interpolated coordinate x[i] at local coordinate s
4018 /// at previous timestep t (t=0: present; t>0: previous timestep)
4019 //========================================================================
4020 double FiniteElement::interpolated_x(const unsigned& t,
4021 const Vector<double>& s,
4022 const unsigned& i) const
4023 {
4024 // Find the number of nodes
4025 const unsigned n_node = nnode();
4026 // Find the number of positional types
4027 const unsigned n_position_type = nnodal_position_type();
4028
4029 // Assign storage for the local shape function
4031 // Find the values of shape function
4032 shape(s, psi);
4033
4034 // Initialise value of x
4035 double interpolated_x = 0.0;
4036 // Loop over the local nodes
4037 for (unsigned l = 0; l < n_node; l++)
4038 {
4039 // Loop over the number of dofs
4040 for (unsigned k = 0; k < n_position_type; k++)
4041 {
4043 }
4044 }
4045
4046 return (interpolated_x);
4047 }
4048
4049 //=======================================================================
4050 /// Return FE interpolated position x[] at local coordinate s as Vector
4051 //=======================================================================
4053 Vector<double>& x) const
4054 {
4055 // Find the number of nodes
4056 const unsigned n_node = nnode();
4057 // Find the number of positional types
4058 const unsigned n_position_type = nnodal_position_type();
4059 // Find the dimension stored in the node
4060 const unsigned nodal_dim = nodal_dimension();
4061
4062 // Assign storage for the local shape function
4064 // Find the values of shape function
4065 shape(s, psi);
4066
4067 // Loop over the dimensions
4068 for (unsigned i = 0; i < nodal_dim; i++)
4069 {
4070 // Initilialise value of x[i] to zero
4071 x[i] = 0.0;
4072 // Loop over the local nodes
4073 for (unsigned l = 0; l < n_node; l++)
4074 {
4075 // Loop over the number of dofs
4076 for (unsigned k = 0; k < n_position_type; k++)
4077 {
4078 x[i] += nodal_position_gen(l, k, i) * psi(l, k);
4079 }
4080 }
4081 }
4082 }
4083
4084 //==========================================================================
4085 /// Return FE interpolated position x[] at local coordinate s
4086 /// at previous timestep t as Vector (t=0: present; t>0: previous timestep)
4087 //==========================================================================
4088 void FiniteElement::interpolated_x(const unsigned& t,
4089 const Vector<double>& s,
4090 Vector<double>& x) const
4091 {
4092 // Find the number of nodes
4093 const unsigned n_node = nnode();
4094 // Find the number of positional types
4095 const unsigned n_position_type = nnodal_position_type();
4096 // Find the dimensions of the nodes
4097 const unsigned nodal_dim = nodal_dimension();
4098
4099 // Assign storage for the local shape function
4101 // Find the values of shape function
4102 shape(s, psi);
4103
4104 // Loop over the dimensions
4105 for (unsigned i = 0; i < nodal_dim; i++)
4106 {
4107 // Initilialise value of x[i] to zero
4108 x[i] = 0.0;
4109 // Loop over the local nodes
4110 for (unsigned l = 0; l < n_node; l++)
4111 {
4112 // Loop over the number of dofs
4113 for (unsigned k = 0; k < n_position_type; k++)
4114 {
4115 x[i] += nodal_position_gen(t, l, k, i) * psi(l, k);
4116 }
4117 }
4118 }
4119 }
4120
4121 //========================================================================
4122 /// Calculate the determinant of the
4123 /// Jacobian of the mapping between local and global
4124 /// coordinates at the position. Works directly from the base vectors
4125 /// without assuming that coordinates match spatial dimension. Will
4126 /// be overloaded in FaceElements, in which the elemental dimension does
4127 /// not match the spatial dimension. WARNING: this is always positive
4128 /// and cannot be used to check if the element is inverted, say!
4129 //========================================================================
4131 {
4132 // Find the number of nodes and position types
4133 const unsigned n_node = nnode();
4134 const unsigned n_position_type = nnodal_position_type();
4135 // Find the dimension of the node and element
4136 const unsigned n_dim_node = nodal_dimension();
4137 const unsigned n_dim_element = dim();
4138
4139 // Set up dummy memory for the shape functions
4142 // Get the shape functions and local derivatives
4144
4145 // Right calculate the base vectors
4148
4149 // Calculate the metric tensor of the element
4151 for (unsigned i = 0; i < n_dim_element; i++)
4152 {
4153 for (unsigned j = 0; j < n_dim_element; j++)
4154 {
4155 for (unsigned k = 0; k < n_dim_node; k++)
4156 {
4157 G(i, j) += interpolated_G(i, k) * interpolated_G(j, k);
4158 }
4159 }
4160 }
4161
4162 // Calculate the determinant of the metric tensor
4163 double det = 0.0;
4164 switch (n_dim_element)
4165 {
4166 case 0:
4167 throw OomphLibError("Cannot calculate J_eulerian() for point element\n",
4170 break;
4171 case 1:
4172 det = G(0, 0);
4173 break;
4174 case 2:
4175 det = G(0, 0) * G(1, 1) - G(0, 1) * G(1, 0);
4176 break;
4177 case 3:
4178 det = G(0, 0) * G(1, 1) * G(2, 2) + G(0, 1) * G(1, 2) * G(2, 0) +
4179 G(0, 2) * G(1, 0) * G(2, 1) - G(0, 0) * G(1, 2) * G(2, 1) -
4180 G(0, 1) * G(1, 0) * G(2, 2) - G(0, 2) * G(1, 1) * G(2, 0);
4181 break;
4182 default:
4183 oomph_info << "More than 3 dimensions in J_eulerian()" << std::endl;
4184 break;
4185 }
4186
4187 // Return the Jacobian (square-root of the determinant of the metric tensor)
4188 return sqrt(det);
4189 }
4190
4191 //========================================================================
4192 /// Compute the Jacobian of the mapping between the local and global
4193 /// coordinates at the ipt-th integration point
4194 //========================================================================
4195 double FiniteElement::J_eulerian_at_knot(const unsigned& ipt) const
4196 {
4197 // Find the number of nodes
4198 const unsigned n_node = nnode();
4199 // Find the number of position types
4200 const unsigned n_position_type = nnodal_position_type();
4201 // Find the dimension of the node and element
4202 const unsigned n_dim_node = nodal_dimension();
4203 const unsigned n_dim_element = dim();
4204
4205 // Set up dummy memory for the shape functions
4208 // Get the shape functions and local derivatives at the knot
4209 // This call may use the stored versions, which is why this entire
4210 // function doesn't just call J_eulerian(s), after reading out s from
4211 // the knots.
4213
4214 // Right calculate the base vectors
4217
4218 // Calculate the metric tensor of the element
4220 for (unsigned i = 0; i < n_dim_element; i++)
4221 {
4222 for (unsigned j = 0; j < n_dim_element; j++)
4223 {
4224 for (unsigned k = 0; k < n_dim_node; k++)
4225 {
4226 G(i, j) += interpolated_G(i, k) * interpolated_G(j, k);
4227 }
4228 }
4229 }
4230
4231 // Calculate the determinant of the metric tensor
4232 double det = 0.0;
4233 switch (n_dim_element)
4234 {
4235 case 0:
4236 throw OomphLibError("Cannot calculate J_eulerian() for point element\n",
4239 break;
4240 case 1:
4241 det = G(0, 0);
4242 break;
4243 case 2:
4244 det = G(0, 0) * G(1, 1) - G(0, 1) * G(1, 0);
4245 break;
4246 case 3:
4247 det = G(0, 0) * G(1, 1) * G(2, 2) + G(0, 1) * G(1, 2) * G(2, 0) +
4248 G(0, 2) * G(1, 0) * G(2, 1) - G(0, 0) * G(1, 2) * G(2, 1) -
4249 G(0, 1) * G(1, 0) * G(2, 2) - G(0, 2) * G(1, 1) * G(2, 0);
4250 break;
4251 default:
4252 oomph_info << "More than 3 dimensions in J_eulerian()" << std::endl;
4253 break;
4254 }
4255
4256 // Return the Jacobian (square-root of the determinant of the metric tensor)
4257 return sqrt(det);
4258 }
4259
4260 //========================================================================
4261 /// Check that Jacobian of mapping between local and Eulerian
4262 /// coordinates at all integration points is positive.
4263 //========================================================================
4265 {
4266 // Bypass check deep down in the guts...
4269
4270 // Let's be optimistic...
4271 passed = true;
4272
4273 // Find the number of nodes
4274 const unsigned n_node = nnode();
4275
4276 // Find the number of position types
4277 const unsigned n_position_type = nnodal_position_type();
4278
4279 // DRAIG: Unused variable
4280 // const unsigned n_dim_node = nodal_dimension();
4281
4282 // Find the dimension of the node and element
4283 const unsigned n_dim_element = dim();
4284
4285 // Set up dummy memory for the shape functions
4288
4289 unsigned nintpt = integral_pt()->nweight();
4290 for (unsigned ipt = 0; ipt < nintpt; ipt++)
4291 {
4293
4294 // Are we dead yet?
4295 if (jac <= 0.0)
4296 {
4297 passed = false;
4298
4299 // Reset
4301
4302 return;
4303 }
4304 }
4305
4306 // Reset
4308 }
4309
4310 //====================================================================
4311 /// Calculate the size of the element (in Eulerian computational
4312 /// coordinates. Use suitably overloaded compute_physical_size()
4313 /// function to compute the actual size (taking into account
4314 /// factors such as 2pi or radii the integrand). Such function
4315 /// can only be implemented on an equation-by-equation basis.
4316 //====================================================================
4317 double FiniteElement::size() const
4318 {
4319 // Initialise the sum to zero
4320 double sum = 0.0;
4321
4322 // Loop over the integration points
4323 const unsigned n_intpt = integral_pt()->nweight();
4324 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
4325 {
4326 // Get the integral weight
4327 double w = integral_pt()->weight(ipt);
4328 // Get the value of the Jacobian of the mapping to global coordinates
4329 double J = J_eulerian_at_knot(ipt);
4330
4331 // Add the product to the sum
4332 sum += w * J;
4333 }
4334
4335 // Return the answer
4336 return (sum);
4337 }
4338
4339 //==================================================================
4340 /// Integrate Vector-valued time-dep function over element
4341 //==================================================================
4344 const double& time,
4345 Vector<double>& integral)
4346 {
4347 // Initialise all components of integral Vector and setup integrand vector
4348 const unsigned ncomponents = integral.size();
4350 for (unsigned i = 0; i < ncomponents; i++)
4351 {
4352 integral[i] = 0.0;
4353 }
4354
4355 // Figure out the global (Eulerian) spatial dimension of the
4356 // element
4357 const unsigned n_dim_eulerian = nodal_dimension();
4358
4359 // Allocate Vector of global Eulerian coordinates
4361
4362 // Set the value of n_intpt
4363 const unsigned n_intpt = integral_pt()->nweight();
4364
4365 // Vector of local coordinates
4366 const unsigned n_dim = dim();
4368
4369 // Loop over the integration points
4370 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
4371 {
4372 // Assign the values of s
4373 for (unsigned i = 0; i < n_dim; i++)
4374 {
4375 s[i] = integral_pt()->knot(ipt, i);
4376 }
4377
4378 // Assign the values of the global Eulerian coordinates
4379 for (unsigned i = 0; i < n_dim_eulerian; i++)
4380 {
4381 x[i] = interpolated_x(s, i);
4382 }
4383
4384 // Get the integral weight
4385 double w = integral_pt()->weight(ipt);
4386
4387 // Get Jacobian of mapping
4388 double J = J_eulerian(s);
4389
4390 // Evaluate the integrand at the knot points
4391 integrand_fct_pt(time, x, integrand);
4392
4393 // Add to components of integral Vector
4394 for (unsigned i = 0; i < ncomponents; i++)
4395 {
4396 integral[i] += integrand[i] * w * J;
4397 }
4398 }
4399 }
4400
4401 //==================================================================
4402 /// Integrate Vector-valued function over element
4403 //==================================================================
4406 Vector<double>& integral)
4407 {
4408 // Initialise all components of integral Vector
4409 const unsigned ncomponents = integral.size();
4411 for (unsigned i = 0; i < ncomponents; i++)
4412 {
4413 integral[i] = 0.0;
4414 }
4415
4416 // Figure out the global (Eulerian) spatial dimension of the
4417 // element by checking the Eulerian dimension of the nodes
4418 const unsigned n_dim_eulerian = nodal_dimension();
4419
4420 // Allocate Vector of global Eulerian coordinates
4422
4423 // Set the value of n_intpt
4424 const unsigned n_intpt = integral_pt()->nweight();
4425
4426 // Vector of local coordinates
4427 const unsigned n_dim = dim();
4429
4430 // Loop over the integration points
4431 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
4432 {
4433 // Assign the values of s
4434 for (unsigned i = 0; i < n_dim; i++)
4435 {
4436 s[i] = integral_pt()->knot(ipt, i);
4437 }
4438
4439 // Assign the values of the global Eulerian coordinates
4440 for (unsigned i = 0; i < n_dim_eulerian; i++)
4441 {
4442 x[i] = interpolated_x(s, i);
4443 }
4444
4445 // Get the integral weight
4446 double w = integral_pt()->weight(ipt);
4447
4448 // Get Jacobian of mapping
4449 double J = J_eulerian(s);
4450
4451 // Evaluate the integrand at the knot points
4453
4454 // Add to components of integral Vector
4455 for (unsigned i = 0; i < ncomponents; i++)
4456 {
4457 integral[i] += integrand[i] * w * J;
4458 }
4459 }
4460 }
4461
4462 //==========================================================================
4463 /// Self-test: Have all internal values been classified as
4464 /// pinned/unpinned? Has pointer to spatial integration scheme
4465 /// been set? Return 0 if OK.
4466 //==========================================================================
4468 {
4469 // Initialise
4470 bool passed = true;
4471
4473 {
4474 passed = false;
4475 }
4476
4477 // Check that pointer to spatial integration scheme has been set
4478 if (integral_pt() == 0)
4479 {
4480 passed = false;
4481
4482 OomphLibWarning("Pointer to spatial integration scheme has not been set.",
4483 "FiniteElement::self_test()",
4485 }
4486
4487 // If the dimension of the element is zero (point element), there
4488 // is not jacobian
4489 const unsigned dim_el = dim();
4490
4491 if (dim_el > 0)
4492 {
4493 // Loop over integration points to check sign of Jacobian
4494 //-------------------------------------------------------
4495
4496 // Set the value of n_intpt
4497 const unsigned n_intpt = integral_pt()->nweight();
4498
4499 // Set the Vector to hold local coordinates
4501
4502 // Find the number of local nodes
4503 const unsigned n_node = nnode();
4504 const unsigned n_position_type = nnodal_position_type();
4505 // Set up memory for the shape and test functions
4508
4509 // Jacobian
4510 double jacobian;
4511
4512
4513 // Two ways of testing for negative Jacobian for non-FaceElements
4514 unsigned ntest = 1;
4515
4516 // For FaceElements checking the Jacobian via dpsidx doesn't
4517 // make sense
4518 FiniteElement* tmp_pt = const_cast<FiniteElement*>(this);
4519 FaceElement* face_el_pt = dynamic_cast<FaceElement*>(tmp_pt);
4520 if (face_el_pt == 0)
4521 {
4522 ntest = 2;
4523 }
4524
4525 // For now overwrite -- the stuff above fails for Bretherton.
4526 // Not sure why.
4527 ntest = 1;
4528
4529 // Loop over the integration points
4530 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
4531 {
4532 // Assign values of s
4533 for (unsigned i = 0; i < dim_el; i++)
4534 {
4535 s[i] = integral_pt()->knot(ipt, i);
4536 }
4537
4538
4539 // Do tests
4540 for (unsigned test = 0; test < ntest; test++)
4541 {
4542 switch (test)
4543 {
4544 case 0:
4545
4546 // Get the jacobian from the mapping between local and Eulerian
4547 // coordinates
4548 jacobian = J_eulerian(s);
4549
4550 break;
4551
4552 case 1:
4553
4554 // Call the geometrical shape functions and derivatives
4555 // This also computes the Jacobian by a slightly different
4556 // method
4557 jacobian = dshape_eulerian_at_knot(ipt, psi, dpsidx);
4558
4559 break;
4560
4561 default:
4562
4563 throw OomphLibError("Never get here",
4566 }
4567
4568
4569 // Check for a singular jacobian
4570 if (std::fabs(jacobian) < 1.0e-16)
4571 {
4572 std::ostringstream warning_stream;
4573 warning_stream << "Determinant of Jacobian matrix is zero at ipt "
4574 << ipt << std::endl;
4576 "FiniteElement::self_test()",
4578 passed = false;
4579 // Skip the next test
4580 continue;
4581 }
4582
4583 // Check sign of Jacobian
4584 if ((Accept_negative_jacobian == false) && (jacobian < 0.0))
4585 {
4586 std::ostringstream warning_stream;
4587 warning_stream << "Jacobian negative at integration point ipt="
4588 << ipt << std::endl;
4590 << "If you think that this is what you want you may: "
4591 << std::endl
4592 << "set the (static) flag "
4593 << "FiniteElement::Accept_negative_jacobian to be true"
4594 << std::endl;
4595
4597 "FiniteElement::self_test()",
4599 passed = false;
4600 }
4601
4602 } // end of loop over two tests
4603 }
4604 } // End of non-zero dimension check
4605
4606 // Return verdict
4607 if (passed)
4608 {
4609 return 0;
4610 }
4611 else
4612 {
4613 return 1;
4614 }
4615 }
4616
4617
4618 //=======================================================================
4619 /// Return the t-th time-derivative of the
4620 /// i-th FE-interpolated Eulerian coordinate at
4621 /// local coordinate s.
4622 //=======================================================================
4624 const unsigned& i,
4625 const unsigned& t_deriv)
4626 {
4627 // Find the number of nodes and positions (locally cached)
4628 const unsigned n_node = nnode();
4629 const unsigned n_position_type = nnodal_position_type();
4630 // Get shape functions: specify # of nodes, # of positional dofs
4632 shape(s, psi);
4633
4634 // Initialise
4635 double drdt = 0.0;
4636
4637 // Assemble time derivative
4638 // Loop over nodes
4639 for (unsigned l = 0; l < n_node; l++)
4640 {
4641 // Loop over types of dof
4642 for (unsigned k = 0; k < n_position_type; k++)
4643 {
4645 }
4646 }
4647 return drdt;
4648 }
4649
4650
4651 //=======================================================================
4652 /// Compute t-th time-derivative of the
4653 /// FE-interpolated Eulerian coordinate vector at
4654 /// local coordinate s.
4655 //=======================================================================
4657 const unsigned& t_deriv,
4659 {
4660 // Find the number of nodes and positions (locally cached)
4661 const unsigned n_node = nnode();
4662 const unsigned n_position_type = nnodal_position_type();
4663 const unsigned nodal_dim = nodal_dimension();
4664
4665 // Get shape functions: specify # of nodes, # of positional dofs
4667 shape(s, psi);
4668
4669 // Loop over directions
4670 for (unsigned i = 0; i < nodal_dim; i++)
4671 {
4672 // Initialise
4673 dxdt[i] = 0.0;
4674
4675 // Assemble time derivative
4676 // Loop over nodes
4677 for (unsigned l = 0; l < n_node; l++)
4678 {
4679 // Loop over types of dof
4680 for (unsigned k = 0; k < n_position_type; k++)
4681 {
4682 dxdt[i] += dnodal_position_gen_dt(t_deriv, l, k, i) * psi(l, k);
4683 }
4684 }
4685 }
4686 }
4687
4688 //============================================================================
4689 /// Calculate the interpolated value of zeta, the intrinsic coordinate
4690 /// of the element when viewed as a compound geometric object within a Mesh
4691 /// as a function of the local coordinate of the element, s.
4692 /// The default
4693 /// assumption is the zeta is interpolated using the shape functions of
4694 /// the element with the values given by zeta_nodal().
4695 /// A MacroElement representation of the intrinsic coordinate parametrised
4696 /// by the local coordinate s is used if available.
4697 /// Choosing the MacroElement representation of zeta (Eulerian x by default)
4698 /// allows a correspondence to be established between elements on different
4699 /// Meshes covering the same curvilinear domain in cases where one element
4700 /// is much coarser than the other.
4701 //==========================================================================
4703 Vector<double>& zeta) const
4704 {
4705 // If there is a macro element use it
4706 if (Macro_elem_pt != 0)
4707 {
4709 }
4710 // Otherwise interpolate zeta_nodal using the shape functions
4711 else
4712 {
4713 // Find the number of nodes
4714 const unsigned n_node = this->nnode();
4715 // Find the number of positional types
4716 const unsigned n_position_type = this->nnodal_position_type();
4717 // Storage for the shape functions
4719 // Get the values of the shape functions at the local coordinate s
4720 this->shape(s, psi);
4721
4722 // Find the number of coordinates
4723 const unsigned ncoord = this->dim();
4724 // Initialise the value of zeta to zero
4725 for (unsigned i = 0; i < ncoord; i++)
4726 {
4727 zeta[i] = 0.0;
4728 }
4729
4730 // Add the contributions from each nodal dof to the interpolated value
4731 // of zeta.
4732 for (unsigned l = 0; l < n_node; l++)
4733 {
4734 for (unsigned k = 0; k < n_position_type; k++)
4735 {
4736 // Locally cache the value of the shape function
4737 const double psi_ = psi(l, k);
4738 for (unsigned i = 0; i < ncoord; i++)
4739 {
4740 zeta[i] += this->zeta_nodal(l, k, i) * psi_;
4741 }
4742 }
4743 }
4744 }
4745 }
4746
4747 //==========================================================================
4748 /// For a given value of zeta, the "global" intrinsic coordinate of
4749 /// a mesh of FiniteElements represented as a compound geometric object,
4750 /// find the local coordinate in this element that corresponds to the
4751 /// requested value of zeta.
4752 /// This is achieved in generality by using Newton's method to find the value
4753 /// of the local coordinate, s, such that
4754 /// interpolated_zeta(s) is equal to the requested value of zeta.
4755 /// If zeta cannot be located in this element, geom_object_pt is set
4756 /// to NULL. If zeta is located in this element, we return its "this"
4757 /// pointer.
4758 /// Setting the optional bool argument to true means that the coordinate
4759 /// argument "s" is used as the initial guess. (Default is false).
4760 //=========================================================================
4762 GeomObject*& geom_object_pt,
4765 {
4766 // Find the number of coordinates, the dimension of the element
4767 // This must be the same for the local and intrinsic global coordinate
4768 unsigned ncoord = this->dim();
4769
4770 // Fast return based on centre of gravity and max. radius of any nodal
4771 // point
4773 0.0)
4774 {
4776 double max_radius = 0.0;
4778
4779 // Get radius
4780 double radius = 0.0;
4781 for (unsigned i = 0; i < ncoord; i++)
4782 {
4783 radius += (cog[i] - zeta[i]) * (cog[i] - zeta[i]);
4784 }
4785 radius = sqrt(radius);
4786 if (radius > Locate_zeta_helpers::
4787 Radius_multiplier_for_fast_exit_from_locate_zeta *
4788 max_radius)
4789 {
4790 geom_object_pt = 0;
4791 return;
4792 }
4793 }
4794
4795 // Assign storage for the vector and matrix used in Newton's method
4796 Vector<double> dx(ncoord, 0.0);
4797 DenseDoubleMatrix jacobian(ncoord, ncoord, 0.0);
4798
4799 // // Make a list of (equally-spaced) local coordinates inside the element
4800 // unsigned n_list=Locate_zeta_helpers::N_local_points;
4801
4802 // double list_space=(1.0/(double(n_list)-1.0))*(s_max()-s_min());
4803
4804 // Possible initial guesses for Newton's method
4806
4807 // If the boolean argument use_coordinate_as_initial_guess was set
4808 // to true then we don't need to initialise s
4810 {
4811 // Vector of local coordinates
4813
4814 // Loop over plot points
4815 unsigned num_plot_points =
4817 for (unsigned iplot = 0; iplot < num_plot_points; iplot++)
4818 {
4819 // Get local coordinates of plot point
4821 s_list.push_back(s_c);
4822 }
4823 }
4824
4825 // Counter for the number of Newton steps
4826 unsigned count = 0;
4827
4828 // Control flag for the Newton loop
4829 bool keep_going = true;
4830
4831 // Storage for the interpolated value of x
4833
4834 // Ifwe have specified the coordinate already
4836 {
4837 // Get the value of x at the initial guess
4838 this->interpolated_zeta(s, inter_x);
4839
4840 // Set up the residuals
4841 for (unsigned i = 0; i < ncoord; i++)
4842 {
4843 dx[i] = zeta[i] - inter_x[i];
4844 }
4845 }
4846 else
4847 {
4848 // Find the smallest residual from the list of coordinates made earlier
4849 double my_min_resid = DBL_MAX;
4853
4854 unsigned n_list_coord = s_list.size();
4855
4856 for (unsigned i_coord = 0; i_coord < n_list_coord; i_coord++)
4857 {
4858 for (unsigned i = 0; i < ncoord; i++)
4859 {
4860 s_local[i] = s_list[i_coord][i];
4861 }
4862 // get_x for this coordinate
4863 this->interpolated_zeta(s_local, work_x);
4864
4865 // calculate residuals
4866 for (unsigned i = 0; i < ncoord; i++)
4867 {
4868 work_dx[i] = zeta[i] - work_x[i];
4869 }
4870
4871 double maxres = std::fabs(
4872 *std::max_element(work_dx.begin(), work_dx.end(), AbsCmp<double>()));
4873
4874 // test against previous residuals
4875 if (maxres < my_min_resid)
4876 {
4877 my_min_resid = maxres;
4878 dx = work_dx;
4879 inter_x = work_x;
4880 s = s_local;
4881 }
4882 }
4883 }
4884
4885 // Main Newton Loop
4886 do // start of do while loop
4887 {
4888 // Increase loop counter
4889 count++;
4890
4891 // Bail out if necessary (without an error for now...)
4893 {
4894 keep_going = false;
4895 continue;
4896 }
4897
4898 // If it's the first time round the loop, check the initial residuals
4899 if (count == 1)
4900 {
4901 double maxres =
4902 std::fabs(*std::max_element(dx.begin(), dx.end(), AbsCmp<double>()));
4903
4904 // If it's small enough exit
4906 {
4907 keep_going = false;
4908 continue;
4909 }
4910 }
4911
4912 // Is there a macro element? If so, assemble the Jacobian by FD-ing
4913 if (macro_elem_pt() != 0)
4914 {
4915 // Assemble jacobian on the fly by finite differencing
4917 Vector<double> r = inter_x; // i.e. the result of previous call to get_x
4918
4919 // Finite difference step
4921
4922 // Storage for calculated r from incremented s
4924
4925 // Loop over s coordinates
4926 for (unsigned i = 0; i < ncoord; i++)
4927 {
4928 // Increment work_s by a small amount
4929 work_s[i] += fd_step;
4930
4931 // Calculate work_r from macro element
4932 this->interpolated_zeta(work_s, work_r);
4933
4934 // Loop over r to fill Jacobian
4935 for (unsigned j = 0; j < ncoord; j++)
4936 {
4937 jacobian(j, i) = -(work_r[j] - r[j]) / fd_step;
4938 }
4939
4940 // Reset work_s
4941 work_s[i] = s[i];
4942 }
4943 }
4944 else // no macro element, so compute Jacobian with shape functions etc.
4945 {
4946 // Compute the entries of the Jacobian matrix
4947 unsigned n_node = this->nnode();
4948 unsigned n_position_type = this->nnodal_position_type();
4951
4952 // Get the local shape functions and their derivatives
4954
4955 // Calculate the values of dxds
4957
4958 // MH: No longer needed
4959 // //This implementation will only work for n_position_type=1
4960 // //since the function nodal_position_gen does not yet exist
4961 // #ifdef PARANOID
4962 // if (n_position_type!=1)
4963 // {
4964 // std::ostringstream error_stream;
4965 // error_stream << "This implementation does not exist
4966 // yet;\n"
4967 // << "it currently uses
4968 // raw_nodal_position_gen\n"
4969 // << "which does not take hangingness into
4970 // account\n"
4971 // << "It will work if n_position_type=1\n";
4972 // throw OomphLibError(error_stream.str(),
4973 // OOMPH_CURRENT_FUNCTION,
4974 // OOMPH_EXCEPTION_LOCATION);
4975 // }
4976 // #endif
4977
4978 // Loop over the nodes
4979 for (unsigned l = 0; l < n_node; l++)
4980 {
4981 // Loop over position type even though it should be 1; the
4982 // functionality for n_position_type>1 will exist in the future
4983 for (unsigned k = 0; k < n_position_type; k++)
4984 {
4985 // Add the contribution from the nodal coordinates to the matrix
4986 for (unsigned i = 0; i < ncoord; i++)
4987 {
4988 for (unsigned j = 0; j < ncoord; j++)
4989 {
4990 interpolated_dxds(i, j) +=
4991 this->zeta_nodal(l, k, i) * dpsids(l, k, j);
4992 }
4993 }
4994 }
4995 }
4996
4997 // The entries of the Jacobian matrix are merely dresiduals/ds
4998 // i.e. \f$ -dx/ds \f$
4999 for (unsigned i = 0; i < ncoord; i++)
5000 {
5001 for (unsigned j = 0; j < ncoord; j++)
5002 {
5003 jacobian(i, j) = -interpolated_dxds(i, j);
5004 }
5005 }
5006 }
5007
5008 // Now solve the damn thing
5009 try
5010 {
5011 jacobian.solve(dx);
5012 }
5013 catch (OomphLibError& error)
5014 {
5015 // I've caught the error so shut up!
5016 error.disable_error_message();
5017#ifdef PARANOID
5018 oomph_info << "Error in linear solve for "
5019 << "FiniteElement::locate_zeta()" << std::endl;
5020 oomph_info << "Should not affect the result!" << std::endl;
5021#endif
5022 }
5023
5024 // Add the correction to the local coordinates
5025 for (unsigned i = 0; i < ncoord; i++)
5026 {
5027 s[i] -= dx[i];
5028 }
5029
5030 // Get the new residuals
5031 this->interpolated_zeta(s, inter_x);
5032 for (unsigned i = 0; i < ncoord; i++)
5033 {
5034 dx[i] = zeta[i] - inter_x[i];
5035 }
5036
5037 // Get the maximum residuals
5038 double maxres =
5039 std::fabs(*std::max_element(dx.begin(), dx.end(), AbsCmp<double>()));
5040
5041 // If we have converged jump straight to the test at the end of the loop
5043 {
5044 keep_going = false;
5045 continue;
5046 }
5047 } while (keep_going);
5048
5049 // Test whether the local coordinates are valid or not
5051
5052 // If not valid, experimentally push back into element
5053 // and see if the result is still valid (within the Newton tolerance)
5054 if (!valid)
5055 {
5057
5058 // Check residuals again
5059 this->interpolated_zeta(s, inter_x);
5060 for (unsigned i = 0; i < ncoord; i++)
5061 {
5062 dx[i] = zeta[i] - inter_x[i];
5063 }
5064
5065 // Get the maximum residuals
5066 double maxres =
5067 std::fabs(*std::max_element(dx.begin(), dx.end(), AbsCmp<double>()));
5068
5069 // Are we still OK?
5071 {
5072 // oomph_info
5073 // << "Pushing back inside has violated the Newton tolerance: max_res =
5074 // "
5075 // << maxres << std::endl;
5076 geom_object_pt = 0;
5077 return;
5078 }
5079 }
5080
5081 // It is also possible now that it may not have converged "correctly",
5082 // i.e. count is greater than Max_newton_iterations
5084 {
5085 // Don't trust the current answer, return null
5086 geom_object_pt = 0;
5087 return;
5088 }
5089
5090 // Otherwise the required point is located in "this" element:
5091 geom_object_pt = this;
5092 }
5093
5094
5095 //=======================================================================
5096 /// Loop over all nodes in the element and update their positions
5097 /// using each node's (algebraic) update function
5098 //=======================================================================
5100 {
5101 const unsigned n_node = nnode();
5102 for (unsigned n = 0; n < n_node; n++)
5103 {
5104 node_pt(n)->node_update();
5105 }
5106 }
5107
5108 //======================================================================
5109 /// The purpose of this function is to identify all possible
5110 /// Data that can affect the fields interpolated by the FiniteElement.
5111 /// The information will typically be used in interaction problems in
5112 /// which the FiniteElement provides a forcing term for an
5113 /// ElementWithExternalElement. The Data must be provided
5114 /// as \c paired_load data containing: (i) the pointer to a Data object
5115 /// (ii) the index of the value in that Data object.
5116 /// The generic implementation (should be overloaded in more specific
5117 /// applications) is to include all nodal and internal Data stored in
5118 /// the FiniteElement. Note that the geometric data,
5119 /// which includes the positions
5120 /// of SolidNodes, is treated separately by the function
5121 /// \c identify_geometric_data()
5122 //======================================================================
5124 std::set<std::pair<Data*, unsigned>>& paired_field_data)
5125 {
5126 // Loop over all internal data
5127 const unsigned n_internal = this->ninternal_data();
5128 for (unsigned n = 0; n < n_internal; n++)
5129 {
5130 // Cache the data pointer
5131 Data* const dat_pt = this->internal_data_pt(n);
5132 // Find the number of data values stored in the data object
5133 const unsigned n_value = dat_pt->nvalue();
5134 // Add the index of each data value and the pointer to the set
5135 // of pairs
5136 for (unsigned i = 0; i < n_value; i++)
5137 {
5138 paired_field_data.insert(std::make_pair(dat_pt, i));
5139 }
5140 }
5141
5142 // Loop over all the nodes
5143 const unsigned n_node = this->nnode();
5144 for (unsigned n = 0; n < n_node; n++)
5145 {
5146 // Cache the node pointer
5147 Node* const nod_pt = this->node_pt(n);
5148 // Find the number of values stored at the node
5149 const unsigned n_value = nod_pt->nvalue();
5150 // Add the index of each data value and the pointer to the set
5151 // of pairs
5152 for (unsigned i = 0; i < n_value; i++)
5153 {
5154 paired_field_data.insert(std::make_pair(nod_pt, i));
5155 }
5156 }
5157 }
5158
5159 void FiniteElement::build_face_element(const int& face_index,
5160 FaceElement* face_element_pt)
5161 {
5162 // Set the nodal dimension
5163 face_element_pt->set_nodal_dimension(nodal_dimension());
5164
5165 // Set the pointer to the orginal "bulk" element
5166 face_element_pt->bulk_element_pt() = this;
5167
5168#ifdef OOMPH_HAS_MPI
5169 // Pass on non-halo proc ID
5170 face_element_pt->set_halo(Non_halo_proc_ID);
5171#endif
5172
5173 // Set the face index
5174 face_element_pt->face_index() = face_index;
5175
5176 // Get number of bulk nodes on a face of this element
5177 const unsigned nnode_face = nnode_on_face();
5178
5179 // Set the function pointer for face coordinate to bulk coordinate
5180 // mapping
5181 face_element_pt->face_to_bulk_coordinate_fct_pt() =
5183
5184 // Set the function pointer for the derivative of the face coordinate to
5185 // bulk coordinate mapping
5186 face_element_pt->bulk_coordinate_derivatives_fct_pt() =
5188
5189 // Resize storage for the number of values originally stored each of the
5190 // face element's nodes.
5191 face_element_pt->nbulk_value_resize(nnode_face);
5192
5193 // Resize storage for the bulk node numbers corresponding to the face
5194 // element's nodes.
5195 face_element_pt->bulk_node_number_resize(nnode_face);
5196
5197 // Copy bulk_node_numbers and nbulk_values
5198 for (unsigned i = 0; i < nnode_face; i++)
5199 {
5200 // Find the corresponding bulk node's number
5201 unsigned bulk_number = get_bulk_node_number(face_index, i);
5202
5203 // Assign the pointer and number into the face element
5204 face_element_pt->node_pt(i) = node_pt(bulk_number);
5205 face_element_pt->bulk_node_number(i) = bulk_number;
5206
5207 // Set the number of values originally stored at this node
5208 face_element_pt->nbulk_value(i) = required_nvalue(bulk_number);
5209 }
5210
5211 // Set the outer unit normal sign
5212 face_element_pt->normal_sign() = face_outer_unit_normal_sign(face_index);
5213 }
5214
5215 //////////////////////////////////////////////////////////////////////////
5216 //////////////////////////////////////////////////////////////////////////
5217 //////////////////////////////////////////////////////////////////////////
5218
5219 // Initialise the static variable.
5220 // Do not ignore warning for discontinuous tangent vectors.
5222
5223
5224 //========================================================================
5225 /// Output boundary coordinate zeta
5226 //========================================================================
5227 void FaceElement::output_zeta(std::ostream& outfile, const unsigned& nplot)
5228 {
5229 // Vector of local coordinates
5230 unsigned n_dim = dim();
5232
5233 // Tecplot header info
5235
5236 // Loop over plot points
5238 for (unsigned iplot = 0; iplot < num_plot_points; iplot++)
5239 {
5240 // Get local coordinates of plot point
5242
5243 // Spatial coordinates are one higher
5244 for (unsigned i = 0; i < n_dim + 1; i++)
5245 {
5246 outfile << interpolated_x(s, i) << " ";
5247 }
5248
5249 // Boundary coordinate
5252 for (unsigned i = 0; i < n_dim; i++)
5253 {
5254 outfile << zeta[i] << " ";
5255 }
5256 outfile << std::endl;
5257 }
5258
5259 // Write tecplot footer (e.g. FE connectivity lists)
5261 }
5262
5263
5264 //========================================================================
5265 /// Calculate the determinant of the
5266 /// Jacobian of the mapping between local and global
5267 /// coordinates at the position s. Overloaded from FiniteElement.
5268 //========================================================================
5270 {
5271 // Find out the sptial dimension of the element
5272 unsigned n_dim_el = this->dim();
5273
5274 // Bail out if we're in a point element -- not sure what
5275 // J_eulerian actually is, but this is harmless
5276 if (n_dim_el == 0) return 1.0;
5277
5278 // Find out how many nodes there are
5279 unsigned n_node = nnode();
5280
5281 // Find out how many positional dofs there are
5282 unsigned n_position_type = this->nnodal_position_type();
5283
5284 // Find out the dimension of the node
5285 unsigned n_dim = this->nodal_dimension();
5286
5287 // Set up memory for the shape functions
5290
5291 // Only need to call the local derivatives
5293
5294 // Also calculate the surface Vectors (derivatives wrt local coordinates)
5296
5297 // Calculate positions and derivatives
5298 for (unsigned l = 0; l < n_node; l++)
5299 {
5300 // Loop over positional dofs
5301 for (unsigned k = 0; k < n_position_type; k++)
5302 {
5303 // Loop over coordinates
5304 for (unsigned i = 0; i < n_dim; i++)
5305 {
5306 // Loop over LOCAL derivative directions, to calculate the tangent(s)
5307 for (unsigned j = 0; j < n_dim_el; j++)
5308 {
5309 interpolated_A(j, i) +=
5311 }
5312 }
5313 }
5314 }
5315 // Now find the local deformed metric tensor from the tangent Vectors
5317 for (unsigned i = 0; i < n_dim_el; i++)
5318 {
5319 for (unsigned j = 0; j < n_dim_el; j++)
5320 {
5321 // Take the dot product
5322 for (unsigned k = 0; k < n_dim; k++)
5323 {
5324 A(i, j) += interpolated_A(i, k) * interpolated_A(j, k);
5325 }
5326 }
5327 }
5328
5329 // Find the determinant of the metric tensor
5330 double Adet = 0.0;
5331 switch (n_dim_el)
5332 {
5333 case 1:
5334 Adet = A(0, 0);
5335 break;
5336 case 2:
5337 Adet = A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
5338 break;
5339 default:
5340 throw OomphLibError("Wrong dimension in FaceElement",
5341 "FaceElement::J_eulerian()",
5343 }
5344
5345 // Return
5346 return sqrt(Adet);
5347 }
5348
5349
5350 //========================================================================
5351 /// Compute the Jacobian of the mapping between the local and global
5352 /// coordinates at the ipt-th integration point. Overloaded from
5353 /// FiniteElement.
5354 //========================================================================
5355 double FaceElement::J_eulerian_at_knot(const unsigned& ipt) const
5356 {
5357 // Find the number of nodes
5358 const unsigned n_node = nnode();
5359
5360 // Find the number of position types
5361 const unsigned n_position_type = nnodal_position_type();
5362
5363 // Find the dimension of the node and element
5364 const unsigned n_dim = nodal_dimension();
5365 const unsigned n_dim_el = dim();
5366
5367 // Set up dummy memory for the shape functions
5370
5371 // Get the shape functions and local derivatives at the knot
5372 // This call may use the stored versions, which is why this entire
5373 // function doesn't just call J_eulerian(s), after reading out s from
5374 // the knots.
5376
5377 // Also calculate the surface Vectors (derivatives wrt local coordinates)
5379
5380 // Calculate positions and derivatives
5381 for (unsigned l = 0; l < n_node; l++)
5382 {
5383 // Loop over positional dofs
5384 for (unsigned k = 0; k < n_position_type; k++)
5385 {
5386 // Loop over coordinates
5387 for (unsigned i = 0; i < n_dim; i++)
5388 {
5389 // Loop over LOCAL derivative directions, to calculate the tangent(s)
5390 for (unsigned j = 0; j < n_dim_el; j++)
5391 {
5392 interpolated_A(j, i) +=
5394 }
5395 }
5396 }
5397 }
5398
5399 // Now find the local deformed metric tensor from the tangent Vectors
5401 for (unsigned i = 0; i < n_dim_el; i++)
5402 {
5403 for (unsigned j = 0; j < n_dim_el; j++)
5404 {
5405 // Take the dot product
5406 for (unsigned k = 0; k < n_dim; k++)
5407 {
5408 A(i, j) += interpolated_A(i, k) * interpolated_A(j, k);
5409 }
5410 }
5411 }
5412
5413 // Find the determinant of the metric tensor
5414 double Adet = 0.0;
5415 switch (n_dim_el)
5416 {
5417 case 1:
5418 Adet = A(0, 0);
5419 break;
5420 case 2:
5421 Adet = A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
5422 break;
5423 default:
5424 throw OomphLibError("Wrong dimension in FaceElement",
5425 "FaceElement::J_eulerian_at_knot()",
5427 }
5428
5429 // Return
5430 return sqrt(Adet);
5431 }
5432
5433 //========================================================================
5434 /// Check that Jacobian of mapping between local and Eulerian
5435 /// coordinates at all integration points is positive.
5436 //========================================================================
5438 {
5439 // Let's be optimistic...
5440 passed = true;
5441
5442 // Find the number of nodes
5443 const unsigned n_node = nnode();
5444
5445 // Find the number of position types
5446 const unsigned n_position_type = nnodal_position_type();
5447
5448 // Find the dimension of the node and element
5449 const unsigned n_dim = nodal_dimension();
5450 const unsigned n_dim_el = dim();
5451
5452 // Set up dummy memory for the shape functions
5455
5456
5457 unsigned nintpt = integral_pt()->nweight();
5458 for (unsigned ipt = 0; ipt < nintpt; ipt++)
5459 {
5460 // Get the shape functions and local derivatives at the knot
5461 // This call may use the stored versions, which is why this entire
5462 // function doesn't just call J_eulerian(s), after reading out s from
5463 // the knots.
5465
5466 // Also calculate the surface Vectors (derivatives wrt local coordinates)
5468
5469 // Calculate positions and derivatives
5470 for (unsigned l = 0; l < n_node; l++)
5471 {
5472 // Loop over positional dofs
5473 for (unsigned k = 0; k < n_position_type; k++)
5474 {
5475 // Loop over coordinates
5476 for (unsigned i = 0; i < n_dim; i++)
5477 {
5478 // Loop over LOCAL derivative directions, to calculate the
5479 // tangent(s)
5480 for (unsigned j = 0; j < n_dim_el; j++)
5481 {
5482 interpolated_A(j, i) +=
5484 dpsids(l, k, j);
5485 }
5486 }
5487 }
5488 }
5489
5490 // Now find the local deformed metric tensor from the tangent Vectors
5492 for (unsigned i = 0; i < n_dim_el; i++)
5493 {
5494 for (unsigned j = 0; j < n_dim_el; j++)
5495 {
5496 // Take the dot product
5497 for (unsigned k = 0; k < n_dim; k++)
5498 {
5499 A(i, j) += interpolated_A(i, k) * interpolated_A(j, k);
5500 }
5501 }
5502 }
5503
5504 // Find the determinant of the metric tensor
5505 double Adet = 0.0;
5506 switch (n_dim_el)
5507 {
5508 case 1:
5509 Adet = A(0, 0);
5510 break;
5511 case 2:
5512 Adet = A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
5513 break;
5514 default:
5515 throw OomphLibError("Wrong dimension in FaceElement",
5516 "FaceElement::J_eulerian_at_knot()",
5518 }
5519
5520
5521 // Are we dead yet?
5522 if (Adet <= 0.0)
5523 {
5524 passed = false;
5525 return;
5526 }
5527 }
5528 }
5529
5530 //=======================================================================
5531 /// Compute the tangent vector(s) and the outer unit normal
5532 /// vector at the specified local coordinate.
5533 /// In two spatial dimensions, a "tangent direction" is not required.
5534 /// In three spatial dimensions, a tangent direction is required
5535 /// (set via set_tangent_direction(...)), and we project the tanent direction
5536 /// on to the surface. The second tangent vector is taken to be the cross
5537 /// product of the projection and the unit normal.
5538 //=======================================================================
5540 const Vector<double>& s,
5543 {
5544 // Find the spatial dimension of the FaceElement
5545 const unsigned element_dim = dim();
5546
5547 // Find the overall dimension of the problem
5548 //(assume that it's the same for all nodes)
5549 const unsigned spatial_dim = nodal_dimension();
5550
5551#ifdef PARANOID
5552 // Check the number of local coordinates passed
5553 if (s.size() != element_dim)
5554 {
5555 std::ostringstream error_stream;
5557 << "Local coordinate s passed to outer_unit_normal() has dimension "
5558 << s.size() << std::endl
5559 << "but element dimension is " << element_dim << std::endl;
5560
5561 throw OomphLibError(
5563 }
5564
5565 // Check that if the Tangent_direction_pt is set, then
5566 // it is the same length as the spatial dimension.
5567 if (Tangent_direction_pt != 0 &&
5569 {
5570 std::ostringstream error_stream;
5571 error_stream << "Tangent direction vector has dimension "
5572 << Tangent_direction_pt->size() << std::endl
5573 << "but spatial dimension is " << spatial_dim << std::endl;
5574
5575 throw OomphLibError(
5577 }
5578
5579 // Check the dimension of the normal vector
5580 if (unit_normal.size() != spatial_dim)
5581 {
5582 std::ostringstream error_stream;
5583 error_stream << "Unit normal passed to outer_unit_normal() has dimension "
5584 << unit_normal.size() << std::endl
5585 << "but spatial dimension is " << spatial_dim << std::endl;
5586
5587 throw OomphLibError(
5589 }
5590
5591
5592 // The number of tangent vectors.
5593 unsigned ntangent_vec = tang_vec.size();
5594
5595 // For the tangent vector,
5596 // if element_dim = 2, tang_vec is a 2D Vector of length 3.
5597 // if element_dim = 1, tang_vec is a 1D Vector of length 2.
5598 // if element_dim = 0, tang_vec is a 1D Vector of length 1.
5599 switch (element_dim)
5600 {
5601 // Point element, derived from a 1D element.
5602 case 0:
5603 {
5604 // Check that tang_vec is a 1D vector.
5605 if (ntangent_vec != 1)
5606 {
5607 std::ostringstream error_stream;
5609 << "This is a 0D FaceElement, we need one tangent vector.\n"
5610 << "You have given me " << tang_vec.size() << " vector(s).\n";
5611 throw OomphLibError(error_stream.str(),
5614 }
5615 }
5616 break;
5617
5618 // Line element, derived from a 2D element.
5619 case 1:
5620 {
5621 // Check that tang_vec is a 1D vector.
5622 if (ntangent_vec != 1)
5623 {
5624 std::ostringstream error_stream;
5626 << "This is a 1D FaceElement, we need one tangent vector.\n"
5627 << "You have given me " << tang_vec.size() << " vector(s).\n";
5628 throw OomphLibError(error_stream.str(),
5631 }
5632 }
5633 break;
5634
5635 // Plane element, derived from 3D element.
5636 case 2:
5637 {
5638 // Check that tang_vec is a 2D vector.
5639 if (ntangent_vec != 2)
5640 {
5641 std::ostringstream error_stream;
5643 << "This is a 2D FaceElement, we need two tangent vectors.\n"
5644 << "You have given me " << tang_vec.size() << " vector(s).\n";
5645 throw OomphLibError(error_stream.str(),
5648 }
5649 }
5650 break;
5651 // There are no other elements!
5652 default:
5653
5654 throw OomphLibError(
5655 "Cannot have a FaceElement with dimension higher than 2",
5658 break;
5659 }
5660
5661 // Check the lengths of each sub vectors.
5662 for (unsigned vec_i = 0; vec_i < ntangent_vec; vec_i++)
5663 {
5664 if (tang_vec[vec_i].size() != spatial_dim)
5665 {
5666 std::ostringstream error_stream;
5667 error_stream << "This problem has " << spatial_dim
5668 << " spatial dimensions.\n"
5669 << "But the " << vec_i << " tangent vector has size "
5670 << tang_vec[vec_i].size() << std::endl;
5671 throw OomphLibError(
5673 }
5674 }
5675
5676#endif
5677
5678
5679 // Now let's consider the different element dimensions
5680 switch (element_dim)
5681 {
5682 // Point element, derived from a 1D element.
5683 case 0:
5684 {
5685 std::ostringstream error_stream;
5687 << "It is unclear how to calculate a tangent and normal vectors for "
5688 << "a point element.\n";
5689 throw OomphLibError(
5691 }
5692 break;
5693
5694 // Line element, derived from a 2D element, in this case
5695 // the normal is a mess of cross products
5696 // We need an interior direction, so we must find the local
5697 // derivatives in the BULK element
5698 case 1:
5699 {
5700 // Find the number of nodes in the bulk element
5701 const unsigned n_node_bulk = Bulk_element_pt->nnode();
5702 // Find the number of position types in the bulk element
5703 const unsigned n_position_type_bulk =
5705
5706 // Construct the local coordinate in the bulk element
5708 // Get the local coordinates in the bulk element
5710
5711 // Allocate storage for the shape functions and their derivatives wrt
5712 // local coordinates
5715 // Get the value of the shape functions at the given local coordinate
5717
5718 // Calculate all derivatives of the spatial coordinates
5719 // wrt local coordinates
5721
5722 // Loop over all parent nodes
5723 for (unsigned l = 0; l < n_node_bulk; l++)
5724 {
5725 // Loop over all position types in the bulk
5726 for (unsigned k = 0; k < n_position_type_bulk; k++)
5727 {
5728 // Loop over derivative direction
5729 for (unsigned j = 0; j < 2; j++)
5730 {
5731 // Loop over coordinate directions
5732 for (unsigned i = 0; i < spatial_dim; i++)
5733 {
5734 // Compute the spatial derivative
5735 interpolated_dxds(j, i) +=
5737 dpsids(l, k, j);
5738 }
5739 }
5740 }
5741 }
5742
5743 // Initialise the tangent, interior tangent and normal vectors to zero
5744 // The idea is that even if the element is in a two-dimensional space,
5745 // the normal cannot be calculated without embedding the element in
5746 // three dimensions, in which case, the tangent and interior tangent
5747 // will have zero z-components.
5748 Vector<double> tangent(3, 0.0), interior_tangent(3, 0.0),
5749 normal(3, 0.0);
5750
5751 // We must get the relationship between the coordinate along the face
5752 // and the local coordinates in the bulk element
5753 // We must also find an interior direction
5755 unsigned interior_direction = 0;
5757 // Load in the values for the tangents
5758 for (unsigned i = 0; i < spatial_dim; i++)
5759 {
5760 // Tangent to the face is the derivative wrt to the face coordinate
5761 // which is calculated using dsbulk_dsface and the chain rule
5762 tangent[i] = interpolated_dxds(0, i) * dsbulk_dsface(0, 0) +
5763 interpolated_dxds(1, i) * dsbulk_dsface(1, 0);
5764 // Interior tangent to the face is the derivative in the interior
5765 // direction
5767 }
5768
5769 // Now the (3D) normal to the element is the interior tangent
5770 // crossed with the tangent
5772
5773 // We find the line normal by crossing the element normal with the
5774 // tangent
5777
5778 // Copy the appropriate entries into the unit normal
5779 // Two or Three depending upon the spatial dimension of the system
5780 for (unsigned i = 0; i < spatial_dim; i++)
5781 {
5783 }
5784
5785 // Finally normalise unit normal and multiply by the Normal_sign
5787 for (unsigned i = 0; i < spatial_dim; i++)
5788 {
5790 }
5791
5792 // Create the tangent vector
5793 tang_vec[0][0] = -unit_normal[1];
5794 tang_vec[0][1] = unit_normal[0];
5795 }
5796 break;
5797
5798 // Plane element, derived from 3D element, in this case the normal
5799 // is just the cross product of the two surface tangents
5800 // We assume, therefore, that we have three spatial coordinates
5801 // and two surface coordinates
5802 // Then we need only to get the derivatives wrt the local coordinates
5803 // in this face element
5804 case 2:
5805 {
5806#ifdef PARANOID
5807 // Check that we actually have three spatial dimensions
5808 if (spatial_dim != 3)
5809 {
5810 std::ostringstream error_stream;
5811 error_stream << "There are only " << spatial_dim
5812 << "coordinates at the nodes of this 2D FaceElement,\n"
5813 << "which must have come from a 3D Bulk element\n";
5814 throw OomphLibError(error_stream.str(),
5817 }
5818#endif
5819
5820 // Find the number of nodes in the element
5821 const unsigned n_node = this->nnode();
5822 // Find the number of position types
5823 const unsigned n_position_type = this->nnodal_position_type();
5824
5825 // Allocate storage for the shape functions and their derivatives wrt
5826 // local coordinates
5829 // Get the value of the shape functions at the given local coordinate
5830 this->dshape_local(s, psi, dpsids);
5831
5832 // Calculate all derivatives of the spatial coordinates
5833 // wrt local coordinates
5835
5836 // Loop over all nodes
5837 for (unsigned l = 0; l < n_node; l++)
5838 {
5839 // Loop over all position types
5840 for (unsigned k = 0; k < n_position_type; k++)
5841 {
5842 // Loop over derivative directions
5843 for (unsigned j = 0; j < 2; j++)
5844 {
5845 // Loop over coordinate directions
5846 for (unsigned i = 0; i < 3; i++)
5847 {
5848 // Compute the spatial derivative
5849 // Remember that we need to translate the position type
5850 // to its location in the bulk node
5851 interpolated_dxds[j][i] +=
5853 dpsids(l, k, j);
5854 }
5855 }
5856 }
5857 }
5858
5859 // We now take the cross product of the two normal vectors
5862
5863 // Finally normalise unit normal
5865
5866 for (unsigned i = 0; i < spatial_dim; i++)
5867 {
5869 }
5870
5871 // Next we create the continuous tangent vectors!
5872 if (Tangent_direction_pt != 0)
5873 // There is a general direction that the first tangent vector should
5874 // follow.
5875 {
5876 // Project the Tangent direction vector onto the surface.
5877 // Project Tangent_direction_pt D onto the plane P defined by
5878 // T1 and T2:
5879 // proj_P(D) = proj_T1(D) + proj_T2(D), where D is
5880 // Tangent_direction_pt, recall that proj_u(v) = (u.v)/(u.u) * u
5881
5882 // Get the direction vector. The vector is NOT copied! :)
5884
5885#ifdef PARANOID
5886 // Check that the angle between the direction vector and the normal
5887 // is not less than 10 degrees
5889 (10.0 * MathematicalConstants::Pi / 180.0))
5890 {
5891 std::ostringstream err_stream;
5892 err_stream << "The angle between the unit normal and the \n"
5893 << "direction vector is less than 10 degrees.";
5894 throw OomphLibError(err_stream.str(),
5897 }
5898#endif
5899
5900 // Calculate the two scalings, (u.v) / (u.u)
5901 double t1_scaling =
5904
5905 double t2_scaling =
5908
5909 // Finish off the projection.
5910 tang_vec[0][0] = t1_scaling * interpolated_dxds[0][0] +
5912 tang_vec[0][1] = t1_scaling * interpolated_dxds[0][1] +
5914 tang_vec[0][2] = t1_scaling * interpolated_dxds[0][2] +
5916
5917 // The second tangent vector is the cross product of
5918 // tang_vec[0] and the normal vector N.
5920
5921 // Normalise the tangent vectors
5922 for (unsigned vec_i = 0; vec_i < 2; vec_i++)
5923 {
5924 // Get the length...
5926
5927 for (unsigned dim_i = 0; dim_i < spatial_dim; dim_i++)
5928 {
5930 }
5931 }
5932 }
5933 else
5934 // A direction for the first tangent vector is not supplied, we do our
5935 // best to keep it continuous. But if the normal vector is aligned with
5936 // the z axis, then the tangent vector may "flip", even within elements.
5937 // This is because we check this by comparing doubles.
5938 // The code is copied from impose_parallel_outflow_element.h,
5939 // NO modification is done except for a few variable name changes.
5940 {
5941 double a, b, c;
5942 a = unit_normal[0];
5943 b = unit_normal[1];
5944 c = unit_normal[2];
5945
5946 if (a != 0.0 || b != 0.0)
5947 {
5948 double a_sq = a * a;
5949 double b_sq = b * b;
5950 double c_sq = c * c;
5951
5952 tang_vec[0][0] = -b / sqrt(a_sq + b_sq);
5953 tang_vec[0][1] = a / sqrt(a_sq + b_sq);
5954 tang_vec[0][2] = 0;
5955
5956 double z = (a_sq + b_sq) / sqrt(a_sq * c_sq + b_sq * c_sq +
5957 (a_sq + b_sq) * (a_sq + b_sq));
5958
5959 tang_vec[1][0] = -(a * c * z) / (a_sq + b_sq);
5960 tang_vec[1][1] = -(b * c * z) / (a_sq + b_sq);
5961 tang_vec[1][2] = z;
5962 // NB : we didn't use the fact that N is normalized,
5963 // that's why we have these unsimplified formulas
5964 }
5965 else if (c != 0.0)
5966 {
5968 {
5969 std::ostringstream warn_stream;
5971 << "I have detected that your normal vector is [0,0,1].\n"
5972 << "Since this function compares against 0.0, you may\n"
5973 << "get discontinuous tangent vectors.";
5977 }
5978
5979 tang_vec[0][0] = 1.0;
5980 tang_vec[0][1] = 0.0;
5981 tang_vec[0][2] = 0.0;
5982
5983 tang_vec[1][0] = 0.0;
5984 tang_vec[1][1] = 1.0;
5985 tang_vec[1][2] = 0.0;
5986 }
5987 else
5988 {
5989 throw OomphLibError("You have a zero normal vector!! ",
5992 }
5993 }
5994 }
5995 break;
5996
5997 default:
5998
5999 throw OomphLibError(
6000 "Cannot have a FaceElement with dimension higher than 2",
6003 break;
6004 }
6005 }
6006
6007 //=======================================================================
6008 /// Compute the tangent vector(s) and the outer unit normal
6009 /// vector at the ipt-th integration point. This is a wrapper around
6010 /// continuous_tangent_and_outer_unit_normal(...) with the integration points
6011 /// converted into local coordinates.
6012 //=======================================================================
6014 const unsigned& ipt,
6017 {
6018 // Find the dimension of the element
6019 const unsigned element_dim = dim();
6020 // Find the local coordinates of the ipt-th integration point
6022 for (unsigned i = 0; i < element_dim; i++)
6023 {
6024 s[i] = integral_pt()->knot(ipt, i);
6025 }
6026 // Call the outer unit normal function
6028 }
6029
6030 //=======================================================================
6031 /// Compute the outer unit normal at the specified local coordinate
6032 //=======================================================================
6035 {
6036 // Find the spatial dimension of the FaceElement
6037 const unsigned element_dim = dim();
6038
6039 // Find the overall dimension of the problem
6040 //(assume that it's the same for all nodes)
6041 const unsigned spatial_dim = nodal_dimension();
6042
6043#ifdef PARANOID
6044 // Check the number of local coordinates passed
6045 if (s.size() != element_dim)
6046 {
6047 std::ostringstream error_stream;
6049 << "Local coordinate s passed to outer_unit_normal() has dimension "
6050 << s.size() << std::endl
6051 << "but element dimension is " << element_dim << std::endl;
6052
6053 throw OomphLibError(
6055 }
6056
6057 // Check the dimension of the normal vector
6058 if (unit_normal.size() != spatial_dim)
6059 {
6060 std::ostringstream error_stream;
6061 error_stream << "Unit normal passed to outer_unit_normal() has dimension "
6062 << unit_normal.size() << std::endl
6063 << "but spatial dimension is " << spatial_dim << std::endl;
6064
6065 throw OomphLibError(
6067 }
6068#endif
6069
6070 /* //The spatial dimension of the bulk element will be element_dim+1
6071 const unsigned bulk_dim = element_dim + 1;
6072
6073 //Find the number of nodes in the bulk element
6074 const unsigned n_node_bulk = Bulk_element_pt->nnode();
6075 //Find the number of position types in the bulk element
6076 const unsigned n_position_type_bulk =
6077 Bulk_element_pt->nnodal_position_type();
6078
6079 //Construct the local coordinate in the bulk element
6080 Vector<double> s_bulk(bulk_dim);
6081 //Set the value of the bulk coordinate that is fixed on the face
6082 //s_bulk[s_fixed_index()] = s_fixed_value();
6083
6084 //Set the other bulk coordinates
6085 //for(unsigned i=0;i<element_dim;i++) {s_bulk[bulk_s_index(i)] = s[i];}
6086
6087 get_local_coordinate_in_bulk(s,s_bulk);
6088
6089 //Allocate storage for the shape functions and their derivatives wrt
6090 //local coordinates
6091 Shape psi(n_node_bulk,n_position_type_bulk);
6092 DShape dpsids(n_node_bulk,n_position_type_bulk,bulk_dim);
6093 //Get the value of the shape functions at the given local coordinate
6094 Bulk_element_pt->dshape_local(s_bulk,psi,dpsids);
6095
6096 //Calculate all derivatives of the spatial coordinates wrt local
6097 coordinates DenseMatrix<double> interpolated_dxds(bulk_dim,spatial_dim);
6098 //Initialise to zero
6099 for(unsigned j=0;j<bulk_dim;j++)
6100 {for(unsigned i=0;i<spatial_dim;i++) {interpolated_dxds(j,i) = 0.0;}}
6101
6102 //Loop over all parent nodes
6103 for(unsigned l=0;l<n_node_bulk;l++)
6104 {
6105 //Loop over all position types in the bulk
6106 for(unsigned k=0;k<n_position_type_bulk;k++)
6107 {
6108 //Loop over derivative direction
6109 for(unsigned j=0;j<bulk_dim;j++)
6110 {
6111 //Loop over coordinate directions
6112 for(unsigned i=0;i<spatial_dim;i++)
6113 {
6114 //Compute the spatial derivative
6115 interpolated_dxds(j,i) +=
6116 Bulk_element_pt->nodal_position_gen(l,k,i)*dpsids(l,k,j);
6117 }
6118 }
6119 }
6120 }*/
6121
6122 // Now let's consider the different element dimensions
6123 switch (element_dim)
6124 {
6125 // Point element, derived from a 1D element, in this case
6126 // the normal is merely the tangent to the bulk element
6127 // and there is only one free coordinate in the bulk element
6128 // Hence we will need to calculate the derivatives wrt the
6129 // local coordinates in the BULK element.
6130 case 0:
6131 {
6132 // Find the number of nodes in the bulk element
6133 const unsigned n_node_bulk = Bulk_element_pt->nnode();
6134 // Find the number of position types in the bulk element
6135 const unsigned n_position_type_bulk =
6137
6138 // Construct the local coordinate in the bulk element
6140
6141 // Get the local coordinates in the bulk element
6143
6144 // Allocate storage for the shape functions and their derivatives wrt
6145 // local coordinates
6148 // Get the value of the shape functions at the given local coordinate
6150
6151 // Calculate all derivatives of the spatial coordinates wrt
6152 // local coordinates
6154
6155 // Loop over all parent nodes
6156 for (unsigned l = 0; l < n_node_bulk; l++)
6157 {
6158 // Loop over all position types in the bulk
6159 for (unsigned k = 0; k < n_position_type_bulk; k++)
6160 {
6161 // Loop over coordinate directions
6162 for (unsigned i = 0; i < spatial_dim; i++)
6163 {
6164 // Compute the spatial derivative
6165 interpolated_dxds(0, i) +=
6167 }
6168 }
6169 }
6170
6171 // Now the unit normal is just the derivative of the position vector
6172 // with respect to the single coordinate
6173 for (unsigned i = 0; i < spatial_dim; i++)
6174 {
6176 }
6177 }
6178 break;
6179
6180 // Line element, derived from a 2D element, in this case
6181 // the normal is a mess of cross products
6182 // We need an interior direction, so we must find the local
6183 // derivatives in the BULK element
6184 case 1:
6185 {
6186 // Find the number of nodes in the bulk element
6187 const unsigned n_node_bulk = Bulk_element_pt->nnode();
6188 // Find the number of position types in the bulk element
6189 const unsigned n_position_type_bulk =
6191
6192 // Construct the local coordinate in the bulk element
6194 // Get the local coordinates in the bulk element
6196
6197 // Allocate storage for the shape functions and their derivatives wrt
6198 // local coordinates
6201 // Get the value of the shape functions at the given local coordinate
6203
6204 // Calculate all derivatives of the spatial coordinates
6205 // wrt local coordinates
6207
6208 // Loop over all parent nodes
6209 for (unsigned l = 0; l < n_node_bulk; l++)
6210 {
6211 // Loop over all position types in the bulk
6212 for (unsigned k = 0; k < n_position_type_bulk; k++)
6213 {
6214 // Loop over derivative direction
6215 for (unsigned j = 0; j < 2; j++)
6216 {
6217 // Loop over coordinate directions
6218 for (unsigned i = 0; i < spatial_dim; i++)
6219 {
6220 // Compute the spatial derivative
6221 interpolated_dxds(j, i) +=
6223 dpsids(l, k, j);
6224 }
6225 }
6226 }
6227 }
6228
6229 // Initialise the tangent, interior tangent and normal vectors to zero
6230 // The idea is that even if the element is in a two-dimensional space,
6231 // the normal cannot be calculated without embedding the element in
6232 // three dimensions, in which case, the tangent and interior tangent
6233 // will have zero z-components.
6234 Vector<double> tangent(3, 0.0), interior_tangent(3, 0.0),
6235 normal(3, 0.0);
6236
6237 // We must get the relationship between the coordinate along the face
6238 // and the local coordinates in the bulk element
6239 // We must also find an interior direction
6241 unsigned interior_direction = 0;
6243 // Load in the values for the tangents
6244 for (unsigned i = 0; i < spatial_dim; i++)
6245 {
6246 // Tangent to the face is the derivative wrt to the face coordinate
6247 // which is calculated using dsbulk_dsface and the chain rule
6248 tangent[i] = interpolated_dxds(0, i) * dsbulk_dsface(0, 0) +
6249 interpolated_dxds(1, i) * dsbulk_dsface(1, 0);
6250 // Interior tangent to the face is the derivative in the interior
6251 // direction
6253 }
6254
6255 // Now the (3D) normal to the element is the interior tangent
6256 // crossed with the tangent
6258
6259 // We find the line normal by crossing the element normal with the
6260 // tangent
6263
6264 // Copy the appropriate entries into the unit normal
6265 // Two or Three depending upon the spatial dimension of the system
6266 for (unsigned i = 0; i < spatial_dim; i++)
6267 {
6269 }
6270 }
6271 break;
6272
6273 // Plane element, derived from 3D element, in this case the normal
6274 // is just the cross product of the two surface tangents
6275 // We assume, therefore, that we have three spatial coordinates
6276 // and two surface coordinates
6277 // Then we need only to get the derivatives wrt the local coordinates
6278 // in this face element
6279 case 2:
6280 {
6281#ifdef PARANOID
6282 // Check that we actually have three spatial dimensions
6283 if (spatial_dim != 3)
6284 {
6285 std::ostringstream error_stream;
6286 error_stream << "There are only " << spatial_dim
6287 << "coordinates at the nodes of this 2D FaceElement,\n"
6288 << "which must have come from a 3D Bulk element\n";
6289 throw OomphLibError(error_stream.str(),
6292 }
6293#endif
6294
6295 // Find the number of nodes in the element
6296 const unsigned n_node = this->nnode();
6297 // Find the number of position types
6298 const unsigned n_position_type = this->nnodal_position_type();
6299
6300 // Allocate storage for the shape functions and their derivatives wrt
6301 // local coordinates
6304 // Get the value of the shape functions at the given local coordinate
6305 this->dshape_local(s, psi, dpsids);
6306
6307 // Calculate all derivatives of the spatial coordinates
6308 // wrt local coordinates
6310
6311 // Loop over all nodes
6312 for (unsigned l = 0; l < n_node; l++)
6313 {
6314 // Loop over all position types
6315 for (unsigned k = 0; k < n_position_type; k++)
6316 {
6317 // Loop over derivative directions
6318 for (unsigned j = 0; j < 2; j++)
6319 {
6320 // Loop over coordinate directions
6321 for (unsigned i = 0; i < 3; i++)
6322 {
6323 // Compute the spatial derivative
6324 // Remember that we need to translate the position type
6325 // to its location in the bulk node
6326 interpolated_dxds[j][i] +=
6328 dpsids(l, k, j);
6329 }
6330 }
6331 }
6332 }
6333
6334 // We now take the cross product of the two normal vectors
6337 }
6338 break;
6339
6340 default:
6341
6342 throw OomphLibError(
6343 "Cannot have a FaceElement with dimension higher than 2",
6346 break;
6347 }
6348
6349 // Finally normalise unit normal
6351 for (unsigned i = 0; i < spatial_dim; i++)
6352 {
6354 }
6355 }
6356
6357 //=======================================================================
6358 /// Compute the outer unit normal at the ipt-th integration point
6359 //=======================================================================
6362 {
6363 // Find the dimension of the element
6364 const unsigned element_dim = dim();
6365 // Find the local coordiantes of the ipt-th integration point
6367 for (unsigned i = 0; i < element_dim; i++)
6368 {
6369 s[i] = integral_pt()->knot(ipt, i);
6370 }
6371 // Call the outer unit normal function
6373 }
6374
6375
6376 //=======================================================================
6377 /// Return vector of local coordinates in bulk element,
6378 /// given the local coordinates in this FaceElement
6379 //=======================================================================
6381 const Vector<double>& s) const
6382 {
6383 // Find the dimension of the bulk element
6384 unsigned dim_bulk = Bulk_element_pt->dim();
6385
6386 // Vector of local coordinates in bulk element
6388
6389 // Use the function pointer if it is set
6391 {
6392 // Call the translation function
6393 (*Face_to_bulk_coordinate_fct_pt)(s, s_bulk);
6394 }
6395 else
6396 {
6397 throw OomphLibError("Face_to_bulk_coordinate mapping not set",
6400 }
6401
6402 // Return it
6403 return s_bulk;
6404 }
6405
6406
6407 //=======================================================================
6408 /// Calculate the vector of local coordinates in bulk element,
6409 /// given the local coordinates in this FaceElement
6410 //=======================================================================
6412 Vector<double>& s_bulk) const
6413 {
6414 // Use the function pointer if it is set
6416 {
6417 // Call the translation function
6418 (*Face_to_bulk_coordinate_fct_pt)(s, s_bulk);
6419 }
6420 // Otherwise use the existing (not general) interface
6421 else
6422 {
6423 throw OomphLibError("Face_to_bulk_coordinate mapping not set",
6426 }
6427 }
6428
6429
6430 //=======================================================================
6431 /// Calculate the derivatives of the local coordinates in the
6432 /// bulk element with respect to the local coordinates in this FaceElement.
6433 /// In addition return the index of a bulk local coordinate that varies away
6434 /// from the face.
6435 //=======================================================================
6438 unsigned& interior_direction) const
6439 {
6440 // Use the function pointer if it is set
6442 {
6443 // Call the translation function
6444 (*Bulk_coordinate_derivatives_fct_pt)(
6446 }
6447 // Otherwise throw an error
6448 else
6449 {
6450 throw OomphLibError(
6451 "No function for derivatives of bulk coords wrt face coords set",
6454 }
6455 }
6456
6457
6458 ///////////////////////////////////////////////////////////////////////////
6459 ///////////////////////////////////////////////////////////////////////////
6460 // Functions for elastic general elements
6461 ///////////////////////////////////////////////////////////////////////////
6462 ///////////////////////////////////////////////////////////////////////////
6463
6464
6465 //==================================================================
6466 /// Calculate the L2 norm of the displacement u=R-r to overload the
6467 /// compute_norm function in the GeneralisedElement base class
6468 //==================================================================
6470 {
6471 // Initialise el_norm to 0.0
6472 el_norm = 0.0;
6473
6474 unsigned n_dim = dim();
6475
6476 // Vector of local coordinates
6478
6479 // Displacement vector, Lagrangian coordinate vector and Eulerian
6480 // coordinate vector respectively
6482 Vector<double> xi(n_dim, 0.0);
6483 Vector<double> x(n_dim, 0.0);
6484
6485 // Find out how many nodes there are in the element
6486 unsigned n_node = this->nnode();
6487
6488 // Construct a shape function
6489 Shape psi(n_node);
6490
6491 // Get the number of integration points
6492 unsigned n_intpt = this->integral_pt()->nweight();
6493
6494 // Loop over the integration points
6495 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
6496 {
6497 // Assign values of s
6498 for (unsigned i = 0; i < n_dim; i++)
6499 {
6500 s[i] = this->integral_pt()->knot(ipt, i);
6501 }
6502
6503 // Get the integral weight
6504 double w = this->integral_pt()->weight(ipt);
6505
6506 // Get jacobian of mapping
6507 double J = this->J_eulerian(s);
6508
6509 // Premultiply the weights and the Jacobian
6510 double W = w * J;
6511
6512 // Get the Lagrangian and Eulerian coordinate at this point, respectively
6513 this->interpolated_xi(s, xi);
6514 this->interpolated_x(s, x);
6515
6516 // Calculate the displacement vector, u=R-r=x-xi
6517 for (unsigned idim = 0; idim < n_dim; idim++)
6518 {
6519 disp[idim] = x[idim] - xi[idim];
6520 }
6521
6522 // Add to norm
6523 for (unsigned ii = 0; ii < n_dim; ii++)
6524 {
6525 el_norm += (disp[ii] * disp[ii]) * W;
6526 }
6527 }
6528 } // End of compute_norm(...)
6529
6530
6531 //=========================================================================
6532 /// Function to describe the local dofs of the element. The ostream
6533 /// specifies the output stream to which the description
6534 /// is written; the string stores the currently
6535 /// assembled output that is ultimately written to the
6536 /// output stream by Data::describe_dofs(...); it is typically
6537 /// built up incrementally as we descend through the
6538 /// call hierarchy of this function when called from
6539 /// Problem::describe_dofs(...)
6540 //=========================================================================
6542 std::ostream& out, const std::string& current_string) const
6543 {
6544 // Call the standard finite element description.
6547 }
6548
6549
6550 //=========================================================================
6551 /// Internal function that is used to assemble the jacobian of the mapping
6552 /// from local coordinates (s) to the lagrangian coordinates (xi), given the
6553 /// derivatives of the shape functions.
6554 //=========================================================================
6556 const DShape& dpsids, DenseMatrix<double>& jacobian) const
6557 {
6558 // Find the the dimension of the element
6559 const unsigned el_dim = dim();
6560 // Find the number of shape functions and shape functions types
6561 // We shall ASSUME (ENFORCE) that Lagrangian coordinates must
6562 // be interpolated through the nodes
6563 const unsigned n_shape = nnode();
6564 const unsigned n_shape_type = nnodal_lagrangian_type();
6565
6566#ifdef PARANOID
6567 // Check for dimensional compatibility
6569 {
6570 std::ostringstream error_message;
6571 error_message << "Dimension mismatch" << std::endl;
6572 error_message << "The elemental dimension: " << el_dim
6573 << " must equal the nodal Lagrangian dimension: "
6575 << " for the jacobian of the mapping to be well-defined"
6576 << std::endl;
6577 throw OomphLibError(
6578 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
6579 }
6580#endif
6581
6582 // Loop over the rows of the jacobian
6583 for (unsigned i = 0; i < el_dim; i++)
6584 {
6585 // Loop over the columns of the jacobian
6586 for (unsigned j = 0; j < el_dim; j++)
6587 {
6588 // Zero the entry
6589 jacobian(i, j) = 0.0;
6590 // Loop over the shape functions
6591 for (unsigned l = 0; l < n_shape; l++)
6592 {
6593 for (unsigned k = 0; k < n_shape_type; k++)
6594 {
6595 // Jacobian is dx_j/ds_i, which is represented by the sum
6596 // over the dpsi/ds_i of the nodal points X j
6597 // Call the Non-hanging version of positions
6598 // This is overloaded in refineable elements
6599 jacobian(i, j) +=
6601 }
6602 }
6603 }
6604 }
6605 }
6606
6607 //=========================================================================
6608 /// Internal function that is used to assemble the jacobian of second
6609 /// derivatives of the the mapping from local coordinates (s) to the
6610 /// lagrangian coordinates (xi), given the second derivatives of the
6611 /// shape functions.
6612 //=========================================================================
6615 {
6616 // Find the the dimension of the element
6617 const unsigned el_dim = dim();
6618 // Find the number of shape functions and shape functions types
6619 // We ENFORCE that Lagrangian coordinates must be interpolated through
6620 // the nodes
6621 const unsigned n_shape = nnode();
6622 const unsigned n_shape_type = nnodal_lagrangian_type();
6623 // Find the number of second derivatives
6624 const unsigned n_row = N2deriv[el_dim];
6625
6626 // Assemble the "jacobian" (d^2 x_j/ds_i^2) for second derivatives of
6627 // shape functions
6628 // Loop over the rows (number of second derivatives)
6629 for (unsigned i = 0; i < n_row; i++)
6630 {
6631 // Loop over the columns (element dimension
6632 for (unsigned j = 0; j < el_dim; j++)
6633 {
6634 // Zero the entry
6635 jacobian2(i, j) = 0.0;
6636 // Loop over the shape functions
6637 for (unsigned l = 0; l < n_shape; l++)
6638 {
6639 // Loop over the shape function types
6640 for (unsigned k = 0; k < n_shape_type; k++)
6641 {
6642 // Add the terms to the jacobian entry
6643 // Call the Non-hanging version of positions
6644 // This is overloaded in refineable elements
6645 jacobian2(i, j) +=
6647 }
6648 }
6649 }
6650 }
6651 }
6652
6653 //============================================================================
6654 /// Destructor for SolidFiniteElement:
6655 //============================================================================
6657 {
6658 // Delete the storage allocated for the positional local equations
6659 delete[] Position_local_eqn;
6660 }
6661
6662
6663 //==========================================================================
6664 /// Calculate the mapping from local to lagrangian coordinates
6665 /// assuming that the coordinates are aligned in the direction of the local
6666 /// coordinates, i.e. there are no cross terms and the jacobian is diagonal.
6667 /// The local derivatives are passed as dpsids and the jacobian and
6668 /// inverse jacobian are returned.
6669 //==========================================================================
6671 const DShape& dpsids,
6672 DenseMatrix<double>& jacobian,
6674 {
6675 // Find the dimension of the element
6676 const unsigned el_dim = dim();
6677 // Find the number of shape functions and shape functions types
6678 // We shall ASSUME (ENFORCE) that Lagrangian coordinates must
6679 // be interpolated through the nodes
6680 const unsigned n_shape = nnode();
6681 const unsigned n_shape_type = nnodal_lagrangian_type();
6682
6683 // In this case we assume that there are no cross terms, that is
6684 // global coordinate 0 is always in the direction of local coordinate 0
6685
6686 // Loop over the coordinates
6687 for (unsigned i = 0; i < el_dim; i++)
6688 {
6689 // Zero the jacobian and inverse jacobian entries
6690 for (unsigned j = 0; j < el_dim; j++)
6691 {
6692 jacobian(i, j) = 0.0;
6693 inverse_jacobian(i, j) = 0.0;
6694 }
6695
6696 // Loop over the shape functions
6697 for (unsigned l = 0; l < n_shape; l++)
6698 {
6699 // Loop over the types of dof
6700 for (unsigned k = 0; k < n_shape_type; k++)
6701 {
6702 // Derivatives are always dx_{i}/ds_{i}
6703 jacobian(i, i) +=
6705 }
6706 }
6707 }
6708
6709 // Now calculate the determinant of the matrix
6710 double det = 1.0;
6711 for (unsigned i = 0; i < el_dim; i++)
6712 {
6713 det *= jacobian(i, i);
6714 }
6715
6716// Report if Matrix is singular, or negative
6717#ifdef PARANOID
6719#endif
6720
6721 // Calculate the inverse mapping (trivial in this case)
6722 for (unsigned i = 0; i < el_dim; i++)
6723 {
6724 inverse_jacobian(i, i) = 1.0 / jacobian(i, i);
6725 }
6726
6727 // Return the value of the Jacobian
6728 return (det);
6729 }
6730
6731 //========================================================================
6732 /// Calculate shape functions and derivatives w.r.t. Lagrangian
6733 /// coordinates at local coordinate s. Returns the Jacobian of the mapping
6734 /// from Lagrangian to local coordinates.
6735 /// General case, may be overloaded
6736 //========================================================================
6738 Shape& psi,
6739 DShape& dpsi) const
6740 {
6741 // Find the element dimension
6742 const unsigned el_dim = dim();
6743
6744 // Get the values of the shape function and local derivatives
6745 // Temporarily stored in dpsi
6747
6748 // Allocate memory for the inverse jacobian
6750 // Now calculate the inverse jacobian
6752
6753 // Now set the values of the derivatives to be dpsidxi
6755 // Return the determinant of the jacobian
6756 return det;
6757 }
6758
6759 //=========================================================================
6760 /// Compute the geometric shape functions and also first
6761 /// derivatives w.r.t. Lagrangian coordinates at integration point ipt.
6762 /// Most general form of function, but may be over-loaded if desired
6763 //========================================================================
6765 Shape& psi,
6766 DShape& dpsi) const
6767 {
6768 // Find the element dimension
6769 const unsigned el_dim = dim();
6770
6771 // Shape function for the local derivatives
6772 // Again we ASSUME (insist) that the lagrangian coordinates
6773 // are interpolated through the nodes
6774 // Get the values of the shape function and local derivatives
6776
6777 // Allocate memory for the inverse jacobian
6779 // Now calculate the inverse jacobian
6781
6782 // Now set the values of the derivatives
6784 // Return the determinant of the jacobian
6785 return det;
6786 }
6787
6788 //========================================================================
6789 /// Compute the geometric shape functions and also first
6790 /// and second derivatives w.r.t. Lagrangian coordinates at
6791 /// local coordinate s;
6792 /// Returns Jacobian of mapping from Lagrangian to local coordinates.
6793 /// Numbering:
6794 /// \b 1D:
6795 /// d2pidxi(i,0) = \f$ d^2 \psi_j / d \xi^2 \f$
6796 /// \b 2D:
6797 /// d2psidxi(i,0) = \f$ \partial^2 \psi_j / \partial \xi_0^2 \f$
6798 /// d2psidxi(i,1) = \f$ \partial^2 \psi_j / \partial \xi_1^2 \f$
6799 /// d2psidxi(i,2) = \f$ \partial^2 \psi_j / \partial \xi_0 \partial \xi_1 \f$
6800 /// \b 3D:
6801 /// d2psidxi(i,0) = \f$ \partial^2 \psi_j / \partial \xi_0^2 \f$
6802 /// d2psidxi(i,1) = \f$ \partial^2 \psi_j / \partial \xi_1^2 \f$
6803 /// d2psidxi(i,2) = \f$ \partial^2 \psi_j / \partial \xi_2^2 \f$
6804 /// d2psidxi(i,3) = \f$ \partial^2 \psi_j/\partial \xi_0 \partial \xi_1 \f$
6805 /// d2psidxi(i,4) = \f$ \partial^2 \psi_j/\partial \xi_0 \partial \xi_2 \f$
6806 /// d2psidxi(i,5) = \f$ \partial^2 \psi_j/\partial \xi_1 \partial \xi_2 \f$
6807 //========================================================================
6809 Shape& psi,
6810 DShape& dpsi,
6811 DShape& d2psi) const
6812 {
6813 // Find the element dimension
6814 const unsigned el_dim = dim();
6815 // Find the number of second derivatives required
6816 const unsigned n_deriv = N2deriv[el_dim];
6817
6818 // Get the values of the shape function and local derivatives
6820
6821 // Allocate memory for the jacobian and inverse jacobian
6823 // Calculate the jacobian and inverse jacobian
6824 const double det =
6826
6827 // Allocate memory for the jacobian of second derivatives
6829 // Assemble the jacobian of second derivatives
6831
6832 // Now set the value of the derivatives
6834 jacobian, inverse_jacobian, jacobian2, dpsi, d2psi);
6835 // Return the determinant of the mapping
6836 return det;
6837 }
6838
6839 //==========================================================================
6840 /// Compute the geometric shape functions and also first
6841 /// and second derivatives w.r.t. Lagrangian coordinates at
6842 /// the ipt-th integration point
6843 /// Returns Jacobian of mapping from Lagrangian to local coordinates.
6844 /// Numbering:
6845 /// \b 1D:
6846 /// d2pidxi(i,0) = \f$ d^2 \psi_j / d \xi^2 \f$
6847 /// \b 2D:
6848 /// d2psidxi(i,0) = \f$ \partial^2 \psi_j / \partial \xi_0^2 \f$
6849 /// d2psidxi(i,1) = \f$ \partial^2 \psi_j / \partial \xi_1^2 \f$
6850 /// d2psidxi(i,2) = \f$ \partial^2 \psi_j/\partial \xi_0 \partial \xi_1 \f$
6851 /// \b 3D:
6852 /// d2psidxi(i,0) = \f$ \partial^2 \psi_j / \partial \xi_0^2 \f$
6853 /// d2psidxi(i,1) = \f$ \partial^2 \psi_j / \partial \xi_1^2 \f$
6854 /// d2psidxi(i,2) = \f$ \partial^2 \psi_j / \partial \xi_2^2 \f$
6855 /// d2psidxi(i,3) = \f$ \partial^2 \psi_j/\partial \xi_0 \partial \xi_1 \f$
6856 /// d2psidxi(i,4) = \f$ \partial^2 \psi_j/\partial \xi_0 \partial \xi_2 \f$
6857 /// d2psidxi(i,5) = \f$ \partial^2 \psi_j/\partial \xi_1 \partial \xi_2 \f$
6858 //========================================================================
6860 Shape& psi,
6861 DShape& dpsi,
6862 DShape& d2psi) const
6863 {
6864 // Find the values of the indices of the shape functions
6865 // Find the element dimension
6866 const unsigned el_dim = dim();
6867 // Find the number of second derivatives required
6868 const unsigned n_deriv = N2deriv[el_dim];
6869
6870 // Get the values of the shape function and local derivatives
6872
6873 // Allocate memory for the jacobian and inverse jacobian
6875 // Calculate the jacobian and inverse jacobian
6876 const double det =
6878
6879 // Allocate memory for the jacobian of second derivatives
6881 // Assemble the jacobian of second derivatives
6883
6884 // Now set the value of the derivatives
6886 jacobian, inverse_jacobian, jacobian2, dpsi, d2psi);
6887 // Return the determinant of the mapping
6888 return det;
6889 }
6890
6891 //============================================================================
6892 /// Function to describe the local dofs of the element. The ostream
6893 /// specifies the output stream to which the description
6894 /// is written; the string stores the currently
6895 /// assembled output that is ultimately written to the
6896 /// output stream by Data::describe_dofs(...); it is typically
6897 /// built up incrementally as we descend through the
6898 /// call hierarchy of this function when called from
6899 /// Problem::describe_dofs(...)
6900 //============================================================================
6902 std::ostream& out, const std::string& current_string) const
6903 {
6904 // Find the number of nodes
6905 const unsigned n_node = nnode();
6906 // Loop over the nodes
6907 for (unsigned n = 0; n < n_node; n++)
6908 {
6909 // Cast to a solid node
6910 SolidNode* cast_node_pt = static_cast<SolidNode*>(node_pt(n));
6911 std::stringstream conversion;
6912 conversion << " of Solid Node " << n << current_string;
6913 std::string in(conversion.str());
6915 }
6916 }
6917
6918 //============================================================================
6919 /// Assign local equation numbers for the solid equations in the element.
6920 /// If the boolean argument is true then pointers to the dofs will be
6921 /// stored in Dof_pt.
6922 // This can be done at a high level assuming, as I am, that the equations
6923 // will always be formulated in terms of nodal positions.
6924 //============================================================================
6926 const bool& store_local_dof_pt)
6927 {
6928 // Find the number of nodes
6929 const unsigned n_node = nnode();
6930
6931 // Check there are nodes!
6932 if (n_node > 0)
6933 {
6934 // Find the number of position types and dimensions of the nodes
6935 // Local caching
6936 const unsigned n_position_type = nnodal_position_type();
6937 const unsigned nodal_dim = nodal_dimension();
6938
6939 // Delete the existing storage
6940 delete[] Position_local_eqn;
6941 // Resize the storage for the positional equation numbers
6943
6944 // A local queue to store the global equation numbers
6945 std::deque<unsigned long> global_eqn_number_queue;
6946
6947 // Get the number of dofs so far, this must be outside both loops
6948 // so that both can use it
6949 unsigned local_eqn_number = ndof();
6950
6951 // Loop over the nodes
6952 for (unsigned n = 0; n < n_node; n++)
6953 {
6954 // Cast to a solid node
6955 SolidNode* cast_node_pt = static_cast<SolidNode*>(node_pt(n));
6956
6957 // Loop over the number of position dofs
6958 for (unsigned j = 0; j < n_position_type; j++)
6959 {
6960 // Loop over the dimension of each node
6961 for (unsigned k = 0; k < nodal_dim; k++)
6962 {
6963 // Get equation number
6964 // Note eqn_number is long !
6965 long eqn_number = cast_node_pt->position_eqn_number(j, k);
6966 // If equation_number positive add to array
6967 if (eqn_number >= 0)
6968 {
6969 // Add to global array
6971 // Add pointer to the dof to the queue if required
6973 {
6975 &(cast_node_pt->x_gen(j, k)));
6976 }
6977
6978 // Add to look-up scheme
6981 // Increment the local equation number
6983 }
6984 else
6985 {
6988 }
6989 }
6990 }
6991 } // End of loop over nodes
6992
6993 // Now add our global equations numbers to the internal element storage
6996 // Clear the memory used in the deque
6998 {
6999 std::deque<double*>().swap(GeneralisedElement::Dof_pt_deque);
7000 }
7001
7002 } // End of the case when there are nodes
7003 }
7004
7005
7006 //============================================================================
7007 /// This function calculates the entries of Jacobian matrix, used in
7008 /// the Newton method, associated with the elastic problem in which the
7009 /// nodal position is a variable. It does this using finite differences,
7010 /// rather than an analytical formulation, so can be done in total generality.
7011 //==========================================================================
7014 {
7015 // Flag to indicate if we use first or second order FD
7016 // bool use_first_order_fd=false;
7017
7018 // Find the number of nodes
7019 const unsigned n_node = nnode();
7020
7021 // If there aren't any nodes, then return straight away
7022 if (n_node == 0)
7023 {
7024 return;
7025 }
7026
7027 // Call the update function to ensure that the element is in
7028 // a consistent state before finite differencing starts
7030
7031 // Get the number of position dofs and dimensions at the node
7032 const unsigned n_position_type = nnodal_position_type();
7033 const unsigned nodal_dim = nodal_dimension();
7034
7035 // Find the number of dofs in the element
7036 const unsigned n_dof = this->ndof();
7037
7038 // Create newres vectors
7040 // Vector<double> newres_minus(n_dof);
7041
7042 // Integer storage for local unknown
7043 int local_unknown = 0;
7044
7045 // Should probably give this a more global scope
7046 const double fd_step = Default_fd_jacobian_step;
7047
7048 // Loop over the nodes
7049 for (unsigned n = 0; n < n_node; n++)
7050 {
7051 // Loop over position dofs
7052 for (unsigned k = 0; k < n_position_type; k++)
7053 {
7054 // Loop over dimension
7055 for (unsigned i = 0; i < nodal_dim; i++)
7056 {
7057 // If the variable is free
7059 if (local_unknown >= 0)
7060 {
7061 // Store a pointer to the (generalised) Eulerian nodal position
7062 double* const value_pt = &(node_pt(n)->x_gen(k, i));
7063
7064 // Save the old value of the (generalised) Eulerian nodal position
7065 const double old_var = *value_pt;
7066
7067 // Increment the (generalised) Eulerian nodal position
7068 *value_pt += fd_step;
7069
7070 // Perform any auxialiary node updates
7072
7073 // Update any other dependent variables
7075
7076 // Calculate the new residuals
7078
7079 // if (use_first_order_fd)
7080 {
7081 // Do forward finite differences
7082 for (unsigned m = 0; m < n_dof; m++)
7083 {
7084 // Stick the entry into the Jacobian matrix
7085 jacobian(m, local_unknown) =
7086 (newres[m] - residuals[m]) / fd_step;
7087 }
7088 }
7089 // else
7090 // {
7091 // //Take backwards step for the (generalised) Eulerian
7092 // nodal
7093 // // position
7094 // node_pt(n)->x_gen(k,i) = old_var-fd_step;
7095
7096 // //Calculate the new residuals at backward position
7097 // get_residuals(newres_minus);
7098
7099 // //Do central finite differences
7100 // for(unsigned m=0;m<n_dof;m++)
7101 // {
7102 // //Stick the entry into the Jacobian matrix
7103 // jacobian(m,local_unknown) =
7104 // (newres[m] - newres_minus[m])/(2.0*fd_step);
7105 // }
7106 // }
7107
7108 // Reset the (generalised) Eulerian nodal position
7109 *value_pt = old_var;
7110
7111
7112 // Perform any auxialiary node updates
7114
7115 // Reset any other dependent variables
7117 }
7118 }
7119 }
7120 }
7121
7122 // End of finite difference loop
7123 // Final reset of any dependent data
7125 }
7126
7127 //============================================================================
7128 /// Return i-th FE-interpolated Lagrangian coordinate at
7129 /// local coordinate s.
7130 //============================================================================
7132 const unsigned& i) const
7133 {
7134 // Find the number of nodes
7135 const unsigned n_node = nnode();
7136
7137 // Find the number of lagrangian types from the first node
7138 const unsigned n_lagrangian_type = nnodal_lagrangian_type();
7139
7140 // Assign storage for the local shape function
7142
7143 // Find the values of shape function
7144 shape(s, psi);
7145
7146 // Initialise value of xi
7147 double interpolated_xi = 0.0;
7148
7149 // Loop over the local nodes
7150 for (unsigned l = 0; l < n_node; l++)
7151 {
7152 // Loop over the number of dofs
7153 for (unsigned k = 0; k < n_lagrangian_type; k++)
7154 {
7156 }
7157 }
7158
7159 return (interpolated_xi);
7160 }
7161
7162 //============================================================================
7163 /// Compute FE-interpolated Lagrangian coordinate vector xi[] at
7164 /// local coordinate s.
7165 //============================================================================
7167 Vector<double>& xi) const
7168 {
7169 // Find the number of nodes
7170 const unsigned n_node = nnode();
7171
7172 // Find the number of lagrangian types from the first node
7173 const unsigned n_lagrangian_type = nnodal_lagrangian_type();
7174
7175 // Assign storage for the local shape function
7177
7178 // Find the values of shape function
7179 shape(s, psi);
7180
7181 // Read out the number of lagrangian coordinates from the node
7182 const unsigned n_lagrangian = lagrangian_dimension();
7183
7184 // Loop over the number of lagrangian coordinates
7185 for (unsigned i = 0; i < n_lagrangian; i++)
7186 {
7187 // Initialise component to zero
7188 xi[i] = 0.0;
7189
7190 // Loop over the local nodes
7191 for (unsigned l = 0; l < n_node; l++)
7192 {
7193 // Loop over the number of dofs
7194 for (unsigned k = 0; k < n_lagrangian_type; k++)
7195 {
7196 xi[i] += lagrangian_position_gen(l, k, i) * psi(l, k);
7197 }
7198 }
7199 }
7200 }
7201
7202
7203 //============================================================================
7204 /// Compute derivatives of FE-interpolated Lagrangian coordinates xi
7205 /// with respect to local coordinates: dxids[i][j]=dxi_i/ds_j
7206 //============================================================================
7209 {
7210 // Find the number of nodes
7211 const unsigned n_node = nnode();
7212
7213 // Find the number of lagrangian types from the first node
7214 const unsigned n_lagrangian_type = nnodal_lagrangian_type();
7215
7216 // Dimension of the element = number of local coordinates
7217 unsigned el_dim = dim();
7218
7219 // Assign storage for the local shape function
7222
7223 // Find the values of shape function and its derivs w.r.t. to local coords
7225
7226 // Read out the number of lagrangian coordinates from the node
7227 const unsigned n_lagrangian = lagrangian_dimension();
7228
7229 // Loop over the number of lagrangian and local coordinates
7230 for (unsigned i = 0; i < n_lagrangian; i++)
7231 {
7232 for (unsigned j = 0; j < el_dim; j++)
7233 {
7234 // Initialise component to zero
7235 dxids(i, j) = 0.0;
7236
7237 // Loop over the local nodes
7238 for (unsigned l = 0; l < n_node; l++)
7239 {
7240 // Loop over the number of dofs
7241 for (unsigned k = 0; k < n_lagrangian_type; k++)
7242 {
7243 dxids(i, j) += lagrangian_position_gen(l, k, i) * dpsi(l, k, j);
7244 }
7245 }
7246 }
7247 }
7248 }
7249
7250 //=======================================================================
7251 /// Add jacobian and residuals for consistent assignment of
7252 /// initial "accelerations" in Newmark scheme. Jacobian is the mass matrix.
7253 //=======================================================================
7255 DenseMatrix<double>& jacobian)
7256 {
7257#ifdef PARANOID
7258 // Check that we're computing the real residuals, not the
7259 // ones corresponding to the assignement of a prescribed displacement
7261 {
7262 std::ostringstream error_stream;
7263 error_stream << "Can only call fill_in_jacobian_for_newmark_accel()\n"
7264 << "With Solve_for_consistent_newmark_accel_flag:"
7266 error_stream << "Solid_ic_pt: " << Solid_ic_pt << std::endl;
7267
7268 throw OomphLibError(
7270 }
7271#endif
7272
7273 // Find the number of nodes
7274 const unsigned n_node = nnode();
7275 const unsigned n_position_type = nnodal_position_type();
7276 const unsigned nodal_dim = nodal_dimension();
7277
7278 // Set the number of Lagrangian coordinates
7279 const unsigned n_lagrangian = dim();
7280
7281 // Integer storage for local equation and unknown
7282 int local_eqn = 0, local_unknown = 0;
7283
7284 // Set up memory for the shape functions:
7285 // # of nodes, # of positional dofs
7287
7288 // # of nodes, # of positional dofs, # of lagrangian coords (for deriv)
7289 // Not needed but they come for free when compute the Jacobian.
7291
7292 // Set # of integration points
7293 const unsigned n_intpt = integral_pt()->nweight();
7294
7295 // Set the Vector to hold local coordinates
7297
7298 // Get positional timestepper from first nodal point
7300
7301#ifdef PARANOID
7302 // Of course all this only works if we're actually using a
7303 // Newmark timestepper!
7304 if (timestepper_pt->type() != "Newmark")
7305 {
7306 std::ostringstream error_stream;
7308 << "Assignment of Newmark accelerations obviously only works\n"
7309 << "for Newmark timesteppers. You've called me with "
7310 << timestepper_pt->type() << std::endl;
7311
7312 throw OomphLibError(
7314 }
7315#endif
7316
7317 // "Acceleration" is the last history value:
7318 const unsigned ntstorage = timestepper_pt->ntstorage();
7319 const double accel_weight = timestepper_pt->weight(2, ntstorage - 1);
7320
7321 // Loop over the integration points
7322 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
7323 {
7324 // Assign values of s
7325 for (unsigned i = 0; i < n_lagrangian; i++)
7326 {
7327 s[i] = integral_pt()->knot(ipt, i);
7328 }
7329
7330 // Get the integral weight
7331 double w = integral_pt()->weight(ipt);
7332
7333 // Jacobian of mapping between local and Lagrangian coords and shape
7334 // functions
7335 double J = dshape_lagrangian(s, psi, dpsidxi);
7336
7337 // Get Lagrangian coordinate
7339 interpolated_xi(s, xi);
7340
7341 // Get multiplier for inertia terms
7342 double factor = multiplier(xi);
7343
7344 // Premultiply the weights and the Jacobian
7345 double W = w * J;
7346
7347 // Loop over the nodes
7348 for (unsigned l0 = 0; l0 < n_node; l0++)
7349 {
7350 // Loop over the positional dofs: 'Type': 0: displacement; 1: deriv
7351 for (unsigned k0 = 0; k0 < n_position_type; k0++)
7352 {
7353 // Loop over Eulerian directions
7354 for (unsigned i0 = 0; i0 < nodal_dim; i0++)
7355 {
7357 // If it's a degree of freedom, add contribution
7358 if (local_eqn >= 0)
7359 {
7360 // Loop over the nodes
7361 for (unsigned l1 = 0; l1 < n_node; l1++)
7362 {
7363 // Loop over the positional dofs: 'Type': 0: displacement;
7364 // 1: deriv
7365 for (unsigned k1 = 0; k1 < n_position_type; k1++)
7366 {
7367 // Loop over Eulerian directions
7368 unsigned i1 = i0;
7369 {
7371 // If it's a degree of freedom, add contribution
7372 if (local_unknown >= 0)
7373 {
7374 // Add contribution: Mass matrix, multiplied by
7375 // weight for "acceleration" in Newmark scheme
7376 // and general multiplier
7377 jacobian(local_eqn, local_unknown) +=
7378 factor * accel_weight * psi(l0, k0) * psi(l1, k1) * W;
7379 }
7380 }
7381 }
7382 }
7383 }
7384 }
7385 }
7386 }
7387
7388 } // End of loop over the integration points
7389 }
7390
7391
7392 //=======================================================================
7393 /// Helper function to fill in the residuals and (if flag==1) the Jacobian
7394 /// for the setup of an initial condition. The global equations are:
7395 /// \f[ 0 = \int \left( \sum_{j=1}^N \sum_{k=1}^K X_{ijk} \psi_{jk}(\xi_n) - \frac{\partial^D R^{(IC)}_i(\xi_n)}{\partial t^D} \right) \psi_{lm}(\xi_n) \ dv \mbox{ \ \ \ \ for \ \ \ $l=1,...,N, \ \ m=1,...,K$} \f]
7396 /// where \f$ N \f$ is the number of nodes in the mesh and \f$ K \f$
7397 /// the number of generalised nodal coordinates. The initial shape
7398 /// of the solid body, \f$ {\bf R}^{(IC)},\f$ and its time-derivatives
7399 /// are specified via the \c GeomObject that is stored in the
7400 /// \c SolidFiniteElement::SolidInitialCondition object. The latter also
7401 /// stores the order of the time-derivative \f$ D \f$ to be assigned.
7402 //=======================================================================
7405 DenseMatrix<double>& jacobian,
7406 const unsigned& flag)
7407 {
7408 // Find the number of nodes and position types
7409 const unsigned n_node = nnode();
7410 const unsigned n_position_type = nnodal_position_type();
7411
7412 // Set the dimension of the global coordinates
7413 const unsigned nodal_dim = nodal_dimension();
7414
7415 // Find the number of lagragian types from the first node
7416 const unsigned n_lagrangian_type = nnodal_lagrangian_type();
7417
7418 // Set the number of lagrangian coordinates
7419 const unsigned n_lagrangian = dim();
7420
7421 // Integer storage for local equation number
7422 int local_eqn = 0;
7423 int local_unknown = 0;
7424
7425 // # of nodes, # of positional dofs
7427
7428 // # of nodes, # of positional dofs, # of lagrangian coords (for deriv)
7429 // not needed but they come for free when we compute the Jacobian
7430 // DShape dpsidxi(n_node,n_position_type,n_lagrangian);
7431
7432 // Set # of integration points
7433 const unsigned n_intpt = integral_pt()->nweight();
7434
7435 // Set the Vector to hold local coordinates
7437
7438 // Loop over the integration points
7439 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
7440 {
7441 // Assign values of s
7442 for (unsigned i = 0; i < n_lagrangian; i++)
7443 {
7444 s[i] = integral_pt()->knot(ipt, i);
7445 }
7446
7447 // Get the integral weight
7448 double w = integral_pt()->weight(ipt);
7449
7450 // Shape fcts
7451 shape(s, psi);
7452
7453 // Get Lagrangian coordinate
7455
7456 // Loop over the number of lagrangian coordinates
7457 for (unsigned i = 0; i < n_lagrangian; i++)
7458 {
7459 // Loop over the local nodes
7460 for (unsigned l = 0; l < n_node; l++)
7461 {
7462 // Loop over the number of dofs
7463 for (unsigned k = 0; k < n_lagrangian_type; k++)
7464 {
7465 xi[i] += lagrangian_position_gen(l, k, i) * psi(l, k);
7466 }
7467 }
7468 }
7469
7470 // Get initial condition
7474
7475 // Weak form of assignment of initial guess
7476
7477 // Loop over the number of node
7478 for (unsigned l = 0; l < n_node; l++)
7479 {
7480 // Loop over the type of degree of freedom
7481 for (unsigned k = 0; k < n_position_type; k++)
7482 {
7483 // Loop over the coordinate directions
7484 for (unsigned i = 0; i < nodal_dim; i++)
7485 {
7487
7488 // If it's not a boundary condition
7489 if (local_eqn >= 0)
7490 {
7491 // Note we're ignoring the mapping between local and
7492 // global Lagrangian coords -- doesn't matter here;
7493 // we're just enforcing a slightly different
7494 // weak form.
7496 (interpolated_x(s, i) - drdt_ic[i]) * psi(l, k) * w;
7497
7498
7499 // Do Jacobian too?
7500 if (flag == 1)
7501 {
7502 // Loop over the number of node
7503 for (unsigned ll = 0; ll < n_node; ll++)
7504 {
7505 // Loop over the type of degree of freedom
7506 for (unsigned kk = 0; kk < n_position_type; kk++)
7507 {
7508 // Only diagonal term
7509 unsigned ii = i;
7510
7512
7513 // If it's not a boundary condition
7514 if (local_unknown >= 0)
7515 {
7516 // Note we're ignoring the mapping between local and
7517 // global Lagrangian coords -- doesn't matter here;
7518 // we're just enforcing a slightly different
7519 // weak form.
7520 jacobian(local_eqn, local_unknown) +=
7521 psi(ll, kk) * psi(l, k) * w;
7522 }
7523 else
7524 {
7526 << "WARNING: You should really free all Data"
7527 << std::endl
7528 << " before setup of initial guess" << std::endl
7529 << "ll, kk, ii " << ll << " " << kk << " " << ii
7530 << std::endl;
7531 }
7532 }
7533 }
7534 }
7535 }
7536 else
7537 {
7538 oomph_info << "WARNING: You should really free all Data"
7539 << std::endl
7540 << " before setup of initial guess"
7541 << std::endl
7542 << "l, k, i " << l << " " << k << " " << i
7543 << std::endl;
7544 }
7545 }
7546 }
7547 }
7548
7549 } // End of loop over the integration points
7550 }
7551
7552
7553 //===============================================================
7554 /// Return the geometric shape function at the local coordinate s
7555 //===============================================================
7557 {
7558 // Single shape function always has value 1
7559 psi[0] = 1.0;
7560 }
7561
7562 //=======================================================================
7563 /// Assign the static Default_integration_scheme
7564 //=======================================================================
7566
7567
7568} // namespace oomph
static char t char * s
Definition cfortran.h:568
cstr elem_len * i
Definition cfortran.h:603
char t
Definition cfortran.h:568
A Class for the derivatives of shape functions The class design is essentially the same as Shape,...
Definition shape.h:359
A class that represents a collection of data; each Data object may contain many different individual ...
Definition nodes.h:86
virtual void add_eqn_numbers_to_vector(Vector< long > &vector_of_eqn_numbers)
Add all equation numbers to the vector in the internal storage order.
Definition nodes.cc:1236
virtual void describe_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the dofs of the Node. The ostream specifies the output stream to which the descr...
Definition nodes.cc:939
virtual void add_value_pt_to_map(std::map< unsigned, double * > &map_of_value_pt)
Add pointers to all unpinned and unconstrained data to a map indexed by (global) equation number.
Definition nodes.cc:1089
static long Is_pinned
Static "Magic number" used in place of the equation number to indicate that the value is pinned.
Definition nodes.h:183
virtual void read_values_from_vector(const Vector< double > &vector_of_values, unsigned &index)
Read all data and time history values from the vector starting from index. On return the index will b...
Definition nodes.cc:1182
virtual void add_values_to_vector(Vector< double > &vector_of_values)
Add all data and time history values to the vector in the internal storage order.
Definition nodes.cc:1112
unsigned nvalue() const
Return number of values stored in data object (incl pinned ones).
Definition nodes.h:483
virtual void assign_eqn_numbers(unsigned long &global_ndof, Vector< double * > &dof_pt)
Assign global equation numbers; increment global number of unknowns, global_ndof; and add any new dof...
Definition nodes.cc:896
static long Is_unclassified
Static "Magic number" used in place of the equation number to denote a value that hasn't been classif...
Definition nodes.h:192
virtual void read_eqn_numbers_from_vector(const Vector< long > &vector_of_eqn_numbers, unsigned &index)
Read all equation numbers from the vector starting from index. On return the index will be set to the...
Definition nodes.cc:1274
double * value_pt(const unsigned &i) const
Return the pointer to the i-the stored value. Typically this is required when direct access to the st...
Definition nodes.h:324
Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functiona...
Definition matrices.h:1312
void solve(DoubleVector &rhs)
Complete LU solve (replaces matrix by its LU decomposition and overwrites RHS with solution)....
Definition matrices.cc:50
This is a base class for all elements that require external sources (e.g. FSI, multi-domain problems ...
FaceElements are elements that coincide with the faces of higher-dimensional "bulk" elements....
Definition elements.h:4342
int & normal_sign()
Sign of outer unit normal (relative to cross-products of tangent vectors in the corresponding "bulk" ...
Definition elements.h:4616
int & face_index()
Index of the face (a number that uniquely identifies the face in the element)
Definition elements.h:4630
void continuous_tangent_and_outer_unit_normal(const Vector< double > &s, Vector< Vector< double > > &tang_vec, Vector< double > &unit_normal) const
Compute the tangent vector(s) and the outer unit normal vector at the specified local coordinate....
Definition elements.cc:5539
FiniteElement * Bulk_element_pt
Pointer to the associated higher-dimensional "bulk" element.
Definition elements.h:4403
void bulk_node_number_resize(const unsigned &i)
Resize the storage for the bulk node numbers.
Definition elements.h:4822
BulkCoordinateDerivativesFctPt & bulk_coordinate_derivatives_fct_pt()
Return the pointer to the function that returns the derivatives of the bulk coordinates wrt the face ...
Definition elements.h:4774
void outer_unit_normal(const Vector< double > &s, Vector< double > &unit_normal) const
Compute outer unit normal at the specified local coordinate.
Definition elements.cc:6033
int Normal_sign
Sign of outer unit normal (relative to cross-products of tangent vectors in the corresponding "bulk" ...
Definition elements.h:4378
BulkCoordinateDerivativesFctPt Bulk_coordinate_derivatives_fct_pt
Pointer to a function that returns the derivatives of the local "bulk" coordinates with respect to th...
Definition elements.h:4365
Vector< double > local_coordinate_in_bulk(const Vector< double > &s) const
Return vector of local coordinates in bulk element, given the local coordinates in this FaceElement.
Definition elements.cc:6380
Vector< double > * Tangent_direction_pt
A general direction pointer for the tangent vectors. This is used in the function continuous_tangent_...
Definition elements.h:4424
unsigned & nbulk_value(const unsigned &n)
Return the number of values originally stored at local node n (before the FaceElement added additiona...
Definition elements.h:4849
double interpolated_x(const Vector< double > &s, const unsigned &i) const
Return FE interpolated coordinate x[i] at local coordinate s. Overloaded to get information from bulk...
Definition elements.h:4532
unsigned & bulk_node_number(const unsigned &n)
Return the bulk node number that corresponds to the n-th local node number.
Definition elements.h:4829
FiniteElement *& bulk_element_pt()
Pointer to higher-dimensional "bulk" element.
Definition elements.h:4739
double J_eulerian(const Vector< double > &s) const
Return the Jacobian of mapping from local to global coordinates at local position s....
Definition elements.cc:5269
static bool Ignore_discontinuous_tangent_warning
Ignores the warning when the tangent vectors from continuous_tangent_and_outer_unit_normal may not be...
Definition elements.h:4388
double J_eulerian_at_knot(const unsigned &ipt) const
Return the Jacobian of the mapping from local to global coordinates at the ipt-th integration point O...
Definition elements.cc:5355
void check_J_eulerian_at_knots(bool &passed) const
Check that Jacobian of mapping between local and Eulerian coordinates at all integration points is po...
Definition elements.cc:5437
unsigned & bulk_position_type(const unsigned &i)
Return the position type in the "bulk" element that corresponds to position type i on the FaceElement...
Definition elements.h:4809
void get_ds_bulk_ds_face(const Vector< double > &s, DenseMatrix< double > &dsbulk_dsface, unsigned &interior_direction) const
Calculate the derivatives of the local coordinates in the bulk element with respect to the local coor...
Definition elements.cc:6436
void get_local_coordinate_in_bulk(const Vector< double > &s, Vector< double > &s_bulk) const
Calculate the vector of local coordinate in the bulk element given the local coordinates in this Face...
Definition elements.cc:6411
CoordinateMappingFctPt Face_to_bulk_coordinate_fct_pt
Pointer to a function that translates the face coordinate to the coordinate in the bulk element.
Definition elements.h:4361
CoordinateMappingFctPt & face_to_bulk_coordinate_fct_pt()
Return the pointer to the function that maps the face coordinate to the bulk coordinate.
Definition elements.h:4759
void output_zeta(std::ostream &outfile, const unsigned &nplot)
Output boundary coordinate zeta.
Definition elements.cc:5227
void nbulk_value_resize(const unsigned &i)
Resize the storage for the number of values originally stored at the local nodes to i entries.
Definition elements.h:4864
A general Finite Element class.
Definition elements.h:1317
virtual double J_eulerian(const Vector< double > &s) const
Return the Jacobian of mapping from local to global coordinates at local position s.
Definition elements.cc:4130
virtual int face_outer_unit_normal_sign(const int &face_index) const
Get the sign of the outer unit normal on the face given by face_index.
Definition elements.h:3384
double d2shape_eulerian(const Vector< double > &s, Shape &psi, DShape &dpsidx, DShape &d2psidx) const
Compute the geometric shape functions and also first and second derivatives w.r.t....
Definition elements.cc:3475
virtual void update_before_nodal_fd()
Function that is called before the finite differencing of any nodal data. This may be overloaded to u...
Definition elements.h:1713
double dJ_eulerian_at_knot(const unsigned &ipt, Shape &psi, DenseMatrix< double > &djacobian_dX) const
Compute the geometric shape functions (psi) at integration point ipt. Return the determinant of the j...
Definition elements.cc:3381
void set_nodal_dimension(const unsigned &nodal_dim)
Set the dimension of the nodes in the element. This will typically only be required when constructing...
Definition elements.h:1394
Integral *const & integral_pt() const
Return the pointer to the integration scheme (const version)
Definition elements.h:1967
virtual void dshape_local_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsids) const
Return the geometric shape function and its derivative w.r.t. the local coordinates at the ipt-th int...
Definition elements.cc:3266
virtual void local_coordinate_of_node(const unsigned &j, Vector< double > &s) const
Get local coordinates of node j in the element; vector sets its own size (broken virtual)
Definition elements.h:1846
Integral * Integral_pt
Pointer to the spatial integration scheme.
Definition elements.h:1320
virtual void transform_derivatives(const DenseMatrix< double > &inverse_jacobian, DShape &dbasis) const
Convert derivative w.r.t.local coordinates to derivatives w.r.t the coordinates used to assemble the ...
Definition elements.cc:2860
virtual unsigned get_bulk_node_number(const int &face_index, const unsigned &i) const
Get the number of the ith node on face face_index (in the bulk node vector).
Definition elements.h:3375
virtual Node * get_node_at_local_coordinate(const Vector< double > &s) const
If there is a node at this local coordinate, return the pointer to the node.
Definition elements.cc:3909
virtual std::string tecplot_zone_string(const unsigned &nplot) const
Return string for tecplot zone header (when plotting nplot points in each "coordinate direction")
Definition elements.h:3165
virtual double s_min() const
Min value of local coordinate.
Definition elements.h:2797
virtual double dshape_eulerian_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsidx) const
Return the geometric shape functions and also first derivatives w.r.t. global coordinates at the ipt-...
Definition elements.cc:3352
unsigned nnodal_position_type() const
Return the number of coordinate types that the element requires to interpolate the geometry between t...
Definition elements.h:2467
virtual void assign_nodal_local_eqn_numbers(const bool &store_local_dof_pt)
Assign the local equation numbers for Data stored at the nodes Virtual so that it can be overloaded b...
Definition elements.cc:3571
virtual void local_fraction_of_node(const unsigned &j, Vector< double > &s_fraction)
Get the local fraction of the node j in the element A dumb, but correct default implementation is pro...
Definition elements.cc:3218
virtual double invert_jacobian_mapping(const DenseMatrix< double > &jacobian, DenseMatrix< double > &inverse_jacobian) const
A template-free interface that takes the matrix passed as jacobian and return its inverse in inverse_...
Definition elements.cc:2193
void interpolated_zeta(const Vector< double > &s, Vector< double > &zeta) const
Calculate the interpolated value of zeta, the intrinsic coordinate of the element when viewed as a co...
Definition elements.cc:4702
virtual void update_in_nodal_fd(const unsigned &i)
Function called within the finite difference loop for nodal data after a change in the i-th nodal val...
Definition elements.h:1722
double dnodal_position_gen_dt(const unsigned &n, const unsigned &k, const unsigned &i) const
i-th component of time derivative (velocity) of the generalised position, dx(k,i)/dt at local node n....
Definition elements.h:2373
virtual double local_to_eulerian_mapping_diagonal(const DShape &dpsids, DenseMatrix< double > &jacobian, DenseMatrix< double > &inverse_jacobian) const
Calculate the mapping from local to Eulerian coordinates given the derivatives of the shape functions...
Definition elements.cc:2615
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
Definition elements.cc:4317
static double Tolerance_for_singular_jacobian
Tolerance below which the jacobian is considered singular.
Definition elements.h:1774
virtual void fill_in_jacobian_from_nodal_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Calculate the contributions to the jacobian from the nodal degrees of freedom using finite difference...
Definition elements.cc:3687
void locate_zeta(const Vector< double > &zeta, GeomObject *&geom_object_pt, Vector< double > &s, const bool &use_coordinate_as_initial_guess=false)
For a given value of zeta, the "global" intrinsic coordinate of a mesh of FiniteElements represented ...
Definition elements.cc:4761
void check_jacobian(const double &jacobian) const
Helper function used to check for singular or negative Jacobians in the transform from local to globa...
Definition elements.cc:1775
virtual void d2shape_local_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsids, DShape &d2psids) const
Return the geometric shape function and its first and second derivatives w.r.t. the local coordinates...
Definition elements.cc:3301
virtual void d2shape_local(const Vector< double > &s, Shape &psi, DShape &dpsids, DShape &d2psids) const
Function to compute the geometric shape functions and also first and second derivatives w....
Definition elements.h:2020
virtual unsigned required_nvalue(const unsigned &n) const
Number of values that must be stored at local node n by the element. The default is 0,...
Definition elements.h:2459
static const double Node_location_tolerance
Default value for the tolerance to be used when locating nodes via local coordinates.
Definition elements.h:1378
virtual void shape(const Vector< double > &s, Shape &psi) const =0
Calculate the geometric shape functions at local coordinate s. This function must be overloaded for e...
virtual double interpolated_x(const Vector< double > &s, const unsigned &i) const
Return FE interpolated coordinate x[i] at local coordinate s.
Definition elements.cc:3989
int nodal_local_eqn(const unsigned &n, const unsigned &i) const
Return the local equation number corresponding to the i-th value at the n-th local node.
Definition elements.h:1436
unsigned dim() const
Return the spatial dimension of the element, i.e. the number of local coordinates required to paramet...
Definition elements.h:2615
MacroElement * Macro_elem_pt
Pointer to the element's macro element (NULL by default)
Definition elements.h:1687
virtual void assemble_local_to_eulerian_jacobian(const DShape &dpsids, DenseMatrix< double > &jacobian) const
Assemble the jacobian matrix for the mapping from local to Eulerian coordinates, given the derivative...
Definition elements.cc:1932
double nodal_position_gen(const unsigned &n, const unsigned &k, const unsigned &i) const
Return the value of the k-th type of the i-th positional variable at the local node n.
Definition elements.h:2353
unsigned nnode() const
Return the number of nodes.
Definition elements.h:2214
virtual double s_max() const
Max. value of local coordinate.
Definition elements.h:2807
unsigned Nodal_dimension
The spatial dimension of the nodes in the element. We assume that nodes have the same spatial dimensi...
Definition elements.h:1340
void(* SteadyExactSolutionFctPt)(const Vector< double > &, Vector< double > &)
Function pointer for function that computes vector-valued steady "exact solution" as .
Definition elements.h:1763
virtual void reset_in_nodal_fd(const unsigned &i)
Function called within the finite difference loop for nodal data after the i-th nodal values is reset...
Definition elements.h:1727
virtual double interpolated_dxdt(const Vector< double > &s, const unsigned &i, const unsigned &t)
Return t-th time-derivative of the i-th FE-interpolated Eulerian coordinate at local coordinate s.
Definition elements.cc:4623
MacroElement * macro_elem_pt()
Access function to pointer to macro element.
Definition elements.h:1882
virtual void get_s_plot(const unsigned &i, const unsigned &nplot, Vector< double > &s, const bool &shifted_to_interior=false) const
Get cector of local coordinates of plot point i (when plotting nplot points in each "coordinate direc...
Definition elements.h:3152
virtual double zeta_nodal(const unsigned &n, const unsigned &k, const unsigned &i) const
Specify the values of the "global" intrinsic coordinate, zeta, of a compound geometric object (a mesh...
Definition elements.h:2726
Node ** Node_pt
Storage for pointers to the nodes in the element.
Definition elements.h:1323
virtual double local_to_eulerian_mapping(const DShape &dpsids, DenseMatrix< double > &jacobian, DenseMatrix< double > &inverse_jacobian) const
Calculate the mapping from local to Eulerian coordinates, given the derivatives of the shape function...
Definition elements.h:1512
virtual BulkCoordinateDerivativesFctPt bulk_coordinate_derivatives_fct_pt(const int &face_index) const
Get a pointer to the derivative of the mapping from face to bulk coordinates.
Definition elements.h:3423
void get_centre_of_gravity_and_max_radius_in_terms_of_zeta(Vector< double > &cog, double &max_radius) const
Compute centre of gravity of all nodes and radius of node that is furthest from it....
Definition elements.cc:3951
virtual unsigned nplot_points(const unsigned &nplot) const
Return total number of plot points (when plotting nplot points in each "coordinate direction")
Definition elements.h:3190
virtual void reset_after_nodal_fd()
Function that is call after the finite differencing of the nodal data. This may be overloaded to rese...
Definition elements.h:1718
double dshape_eulerian(const Vector< double > &s, Shape &psi, DShape &dpsidx) const
Compute the geometric shape functions and also first derivatives w.r.t. global coordinates at local c...
Definition elements.cc:3325
unsigned Elemental_dimension
The spatial dimension of the element, i.e. the number of local coordinates used to parametrize it.
Definition elements.h:1334
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
Definition elements.h:2179
virtual bool local_coord_is_valid(const Vector< double > &s)
Broken assignment operator.
Definition elements.h:1817
void check_J_eulerian_at_knots(bool &passed) const
Check that Jacobian of mapping between local and Eulerian coordinates at all integration points is po...
Definition elements.cc:4264
virtual void dshape_local(const Vector< double > &s, Shape &psi, DShape &dpsids) const
Function to compute the geometric shape functions and derivatives w.r.t. local coordinates at local c...
Definition elements.h:1985
virtual void move_local_coord_back_into_element(Vector< double > &s) const
Adjust local coordinates so that they're located inside the element.
Definition elements.h:1828
virtual void assemble_eulerian_base_vectors(const DShape &dpsids, DenseMatrix< double > &interpolated_G) const
Assemble the covariant Eulerian base vectors, assuming that the derivatives of the shape functions wi...
Definition elements.cc:2036
virtual void assemble_local_to_eulerian_jacobian2(const DShape &d2psids, DenseMatrix< double > &jacobian2) const
Assemble the the "jacobian" matrix of second derivatives of the mapping from local to Eulerian coordi...
Definition elements.cc:1990
virtual void d_dshape_eulerian_dnodal_coordinates(const double &det_jacobian, const DenseMatrix< double > &jacobian, const DenseMatrix< double > &djacobian_dX, const DenseMatrix< double > &inverse_jacobian, const DShape &dpsids, RankFourTensor< double > &d_dpsidx_dX) const
A template-free interface that calculates the derivative w.r.t. the nodal coordinates of the derivat...
Definition elements.cc:2776
virtual double J_eulerian_at_knot(const unsigned &ipt) const
Return the Jacobian of the mapping from local to global coordinates at the ipt-th integration point.
Definition elements.cc:4195
void integrate_fct(FiniteElement::SteadyExactSolutionFctPt integrand_fct_pt, Vector< double > &integral)
Evaluate integral of a Vector-valued function over the element.
Definition elements.cc:4404
virtual void describe_local_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the local dofs of the element[s]. The ostream specifies the output stream to whi...
Definition elements.cc:1734
virtual void build_face_element(const int &face_index, FaceElement *face_element_pt)
Function for building a lower dimensional FaceElement on the specified face of the FiniteElement....
Definition elements.cc:5159
virtual void transform_second_derivatives(const DenseMatrix< double > &jacobian, const DenseMatrix< double > &inverse_jacobian, const DenseMatrix< double > &jacobian2, DShape &dbasis, DShape &d2basis) const
Convert derivatives and second derivatives w.r.t. local coordiantes to derivatives and second derivat...
Definition elements.cc:3152
virtual void describe_nodal_local_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the local dofs of the element[s]. The ostream specifies the output stream to whi...
Definition elements.cc:1752
unsigned nodal_dimension() const
Return the required Eulerian dimension of the nodes in this element.
Definition elements.h:2488
int ** Nodal_local_eqn
Storage for the local equation numbers associated with the values stored at the nodes.
Definition elements.h:1327
virtual ~FiniteElement()
The destructor cleans up the static memory allocated for shape function storage. Internal and externa...
Definition elements.cc:3200
virtual void get_x_from_macro_element(const Vector< double > &s, Vector< double > &x) const
Global coordinates as function of local coordinates using macro element representation....
Definition elements.h:1938
double raw_nodal_position(const unsigned &n, const unsigned &i) const
Return the i-th coordinate at local node n. Do not use the hanging node representation....
Definition elements.cc:1711
virtual void node_update()
Update the positions of all nodes in the element using each node update function. The default impleme...
Definition elements.cc:5099
virtual void write_tecplot_zone_footer(std::ostream &outfile, const unsigned &nplot) const
Add tecplot zone "footer" to output stream (when plotting nplot points in each "coordinate direction"...
Definition elements.h:3178
unsigned Nnode
Number of nodes in the element.
Definition elements.h:1330
virtual void set_integration_scheme(Integral *const &integral_pt)
Set the spatial integration scheme.
Definition elements.cc:3237
static const unsigned N2deriv[]
Static array that holds the number of second derivatives as a function of the dimension of the elemen...
Definition elements.h:1487
static bool Accept_negative_jacobian
Boolean that if set to true allows a negative jacobian in the transform between global and local coor...
Definition elements.h:1779
void(* UnsteadyExactSolutionFctPt)(const double &, const Vector< double > &, Vector< double > &)
Function pointer for function that computes Vector-valued time-dependent function as .
Definition elements.h:1769
virtual unsigned nnode_on_face() const
Definition elements.h:3391
void transform_derivatives_diagonal(const DenseMatrix< double > &inverse_jacobian, DShape &dbasis) const
Convert derivative w.r.t local coordinates to derivatives w.r.t the coordinates used to assemble the ...
Definition elements.cc:2904
double raw_nodal_position_gen(const unsigned &n, const unsigned &k, const unsigned &i) const
Return the value of the k-th type of the i-th positional variable at the local node n....
Definition elements.h:2276
virtual void get_dresidual_dnodal_coordinates(RankThreeTensor< double > &dresidual_dnodal_coordinates)
Compute derivatives of elemental residual vector with respect to nodal coordinates....
Definition elements.cc:3771
static bool Suppress_output_while_checking_for_inverted_elements
Static boolean to suppress output while checking for inverted elements.
Definition elements.h:1783
int get_node_number(Node *const &node_pt) const
Return the number of the node *node_pt if this node is in the element, else return -1;.
Definition elements.cc:3841
virtual void shape_at_knot(const unsigned &ipt, Shape &psi) const
Return the geometric shape function at the ipt-th integration point.
Definition elements.cc:3247
virtual double d2shape_eulerian_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsidx, DShape &d2psidx) const
Return the geometric shape functions and also first and second derivatives w.r.t. global coordinates ...
Definition elements.cc:3529
virtual void identify_field_data_for_interactions(std::set< std::pair< Data *, unsigned > > &paired_field_data)
The purpose of this function is to identify all possible Data that can affect the fields interpolated...
Definition elements.cc:5123
virtual void dJ_eulerian_dnodal_coordinates(const DenseMatrix< double > &jacobian, const DShape &dpsids, DenseMatrix< double > &djacobian_dX) const
A template-free interface that calculates the derivative of the jacobian of a mapping with respect to...
Definition elements.cc:2696
virtual CoordinateMappingFctPt face_to_bulk_coordinate_fct_pt(const int &face_index) const
Get a pointer to the function mapping face coordinates to bulk coordinates.
Definition elements.h:3413
static const unsigned Default_Initial_Nvalue
Default return value for required_nvalue(n) which gives the number of "data" values required by the e...
Definition elements.h:1374
virtual unsigned self_test()
Self-test: Check inversion of element & do self-test for GeneralisedElement. Return 0 if OK.
Definition elements.cc:4467
void fill_in_jacobian_from_external_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
Calculate the contributions to the jacobian from the external degrees of freedom using finite differe...
Definition elements.cc:1224
unsigned nexternal_data() const
Return the number of external data objects.
Definition elements.h:816
virtual void reset_in_external_fd(const unsigned &i)
Function called within the finite difference loop for external data after the values in the i-th exte...
Definition elements.h:488
virtual void fill_in_contribution_to_mass_matrix(Vector< double > &residuals, DenseMatrix< double > &mass_matrix)
Add the elemental contribution to the mass matrix matrix. and the residuals vector....
Definition elements.cc:1317
virtual void update_in_internal_fd(const unsigned &i)
Function called within the finite difference loop for internal data after a change in any values in t...
Definition elements.h:459
bool is_halo() const
Is this element a halo?
Definition elements.h:1150
virtual void reset_after_external_fd()
Function that is call after the finite differencing of the external data. This may be overloaded to r...
Definition elements.h:478
virtual void update_before_external_fd()
Function that is called before the finite differencing of any external data. This may be overloaded t...
Definition elements.h:473
void assign_internal_eqn_numbers(unsigned long &global_number, Vector< double * > &Dof_pt)
Assign the global equation numbers to the internal Data. The arguments are the current highest global...
Definition elements.cc:531
static double Default_fd_jacobian_step
Double used for the default finite difference step in elemental jacobian calculations.
Definition elements.h:1185
static bool Suppress_warning_about_repeated_external_data
Static boolean to suppress warnings about repeated external data. Defaults to true.
Definition elements.h:687
bool internal_data_fd(const unsigned &i) const
Return the status of the boolean flag indicating whether the internal data is included in the finite ...
Definition elements.h:146
unsigned long * Eqn_number
Storage for the global equation numbers represented by the degrees of freedom in the element.
Definition elements.h:77
void read_internal_eqn_numbers_from_vector(const Vector< long > &vector_of_eqn_numbers, unsigned &index)
Read all equation numbers associated with internal data from the vector starting from index....
Definition elements.cc:672
virtual void fill_in_contribution_to_jacobian_and_mass_matrix(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
Add the elemental contribution to the jacobian matrix, mass matrix and the residuals vector....
Definition elements.cc:1347
virtual void fill_in_contribution_to_djacobian_and_dmass_matrix_dparameter(double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam, DenseMatrix< double > &dmass_matrix_dparam)
Add the elemental contribution to the derivative of the jacobian matrix, mass matrix and the residual...
Definition elements.cc:1478
void fill_in_jacobian_from_internal_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
Calculate the contributions to the jacobian from the internal degrees of freedom using finite differe...
Definition elements.cc:1127
Data *& external_data_pt(const unsigned &i)
Return a pointer to i-th external data object.
Definition elements.h:642
bool external_data_fd(const unsigned &i) const
Return the status of the boolean flag indicating whether the external data is included in the finite ...
Definition elements.h:744
virtual void assign_all_generic_local_eqn_numbers(const bool &store_local_dof_pt)
Assign all the local equation numbering schemes that can be applied generically for the element....
Definition elements.h:253
unsigned add_internal_data(Data *const &data_pt, const bool &fd=true)
Add a (pointer to an) internal data object to the element and return the index required to obtain it ...
Definition elements.cc:67
unsigned ndof() const
Return the number of equations/dofs in the element.
Definition elements.h:822
unsigned long eqn_number(const unsigned &ieqn_local) const
Return the global equation number corresponding to the ieqn_local-th local equation number.
Definition elements.h:691
int ** Data_local_eqn
Pointer to array storage for local equation numbers associated with internal and external data....
Definition elements.h:101
Data *& internal_data_pt(const unsigned &i)
Return a pointer to i-th internal data object.
Definition elements.h:605
int local_eqn_number(const unsigned long &ieqn_global) const
Return the local equation number corresponding to the ieqn_global-th global equation number....
Definition elements.h:713
void add_internal_data_values_to_vector(Vector< double > &vector_of_values)
Add all internal data and time history values to the vector in the internal storage order.
Definition elements.cc:630
static DenseMatrix< double > Dummy_matrix
Empty dense matrix used as a dummy argument to combined residual and jacobian functions in the case w...
Definition elements.h:227
virtual void assign_additional_local_eqn_numbers()
Setup any additional look-up schemes for local equation numbers. Examples of use include using local ...
Definition elements.h:263
virtual void get_residuals(Vector< double > &residuals)
Calculate the vector of residuals of the equations in the element. By default initialise the vector t...
Definition elements.h:967
virtual void fill_in_contribution_to_dresiduals_dparameter(double *const &parameter_pt, Vector< double > &dres_dparam)
Add the elemental contribution to the derivatives of the residuals with respect to a parameter....
Definition elements.cc:1383
static bool Suppress_warning_about_any_repeated_data
Static boolean to suppress warnings about repeated data. Defaults to false.
Definition elements.h:679
virtual ~GeneralisedElement()
Virtual destructor to clean up any memory allocated by the object.
Definition elements.cc:281
unsigned ninternal_data() const
Return the number of internal data objects.
Definition elements.h:810
int Non_halo_proc_ID
Non-halo processor ID for Data; -1 if it's not a halo.
Definition elements.h:128
void clear_global_eqn_numbers()
Clear the storage for the global equation numbers and pointers to dofs (if stored)
Definition elements.h:207
unsigned Ninternal_data
Number of internal data.
Definition elements.h:107
unsigned Nexternal_data
Number of external data.
Definition elements.h:110
void add_internal_value_pt_to_map(std::map< unsigned, double * > &map_of_value_pt)
Add pointers to the internal data values to map indexed by the global equation number.
Definition elements.cc:613
void add_global_eqn_numbers(std::deque< unsigned long > const &global_eqn_numbers, std::deque< double * > const &global_dof_pt)
Add the contents of the queue global_eqn_numbers to the local storage for the local-to-global transla...
Definition elements.cc:161
virtual void update_before_internal_fd()
Function that is called before the finite differencing of any internal data. This may be overloaded t...
Definition elements.h:449
virtual void reset_in_internal_fd(const unsigned &i)
Function called within the finite difference loop for internal data after the values in the i-th exte...
Definition elements.h:464
virtual void fill_in_contribution_to_djacobian_dparameter(double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam)
Add the elemental contribution to the derivatives of the elemental Jacobian matrix and residuals with...
Definition elements.cc:1427
virtual void fill_in_contribution_to_hessian_vector_products(Vector< double > const &Y, DenseMatrix< double > const &C, DenseMatrix< double > &product)
Fill in contribution to the product of the Hessian (derivative of Jacobian with respect to all variab...
Definition elements.cc:1528
unsigned Ndof
Number of degrees of freedom.
Definition elements.h:104
int internal_local_eqn(const unsigned &i, const unsigned &j) const
Return the local equation number corresponding to the j-th value stored at the i-th internal data.
Definition elements.h:267
virtual void describe_local_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the local dofs of the element. The ostream specifies the output stream to which ...
Definition elements.cc:575
static std::deque< double * > Dof_pt_deque
Static storage for deque used to add_global_equation_numbers when pointers to the dofs in each elemen...
Definition elements.h:231
virtual void assign_internal_and_external_local_eqn_numbers(const bool &store_local_dof_pt)
Assign the local equation numbers for the internal and external Data This must be called after the gl...
Definition elements.cc:963
virtual void fill_in_contribution_to_inner_products(Vector< std::pair< unsigned, unsigned > > const &history_index, Vector< double > &inner_product)
Fill in the contribution to the inner products between given pairs of history values.
Definition elements.cc:1568
virtual void fill_in_contribution_to_inner_product_vectors(Vector< unsigned > const &history_index, Vector< Vector< double > > &inner_product_vector)
Fill in the contributions to the vectors that when taken as dot product with other history values giv...
Definition elements.cc:1596
void set_halo(const unsigned &non_halo_proc_ID)
Label the element as halo and specify processor that holds non-halo counterpart.
Definition elements.h:1138
void add_internal_eqn_numbers_to_vector(Vector< long > &vector_of_eqn_numbers)
Add all equation numbers associated with internal data to the vector in the internal storage order.
Definition elements.cc:657
virtual void reset_after_internal_fd()
Function that is call after the finite differencing of the internal data. This may be overloaded to r...
Definition elements.h:454
virtual unsigned self_test()
Self-test: Have all internal values been classified as pinned/unpinned? Return 0 if OK.
Definition elements.cc:1628
virtual void assign_local_eqn_numbers(const bool &store_local_dof_pt)
Setup the arrays of local equation numbers for the element. If the optional boolean argument is true,...
Definition elements.cc:693
Data ** Data_pt
Storage for pointers to internal and external data. The data is of the same type and so can be addres...
Definition elements.h:92
static bool Suppress_warning_about_repeated_internal_data
Static boolean to suppress warnings about repeated internal data. Defaults to false.
Definition elements.h:683
double ** Dof_pt
Storage for array of pointers to degrees of freedom ordered by local equation number....
Definition elements.h:84
int external_local_eqn(const unsigned &i, const unsigned &j)
Return the local equation number corresponding to the j-th value stored at the i-th external data.
Definition elements.h:311
void describe_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the dofs of the element. The ostream specifies the output stream to which the de...
Definition elements.cc:553
std::vector< bool > Data_fd
Storage for boolean flags of size Ninternal_data + Nexternal_data that correspond to the data used in...
Definition elements.h:122
void flush_external_data()
Flush all external data.
Definition elements.cc:392
void read_internal_data_values_from_vector(const Vector< double > &vector_of_values, unsigned &index)
Read all internal data and time history values from the vector starting from index....
Definition elements.cc:644
virtual void update_in_external_fd(const unsigned &i)
Function called within the finite difference loop for external data after a change in any values in t...
Definition elements.h:483
unsigned add_external_data(Data *const &data_pt, const bool &fd=true)
Add a (pointer to an) external data object to the element and return its index (i....
Definition elements.cc:312
A geometric object is an object that provides a parametrised description of its shape via the functio...
unsigned ndim() const
Access function to # of Eulerian coordinates.
virtual void dposition_dt(const Vector< double > &zeta, const unsigned &j, Vector< double > &drdt)
j-th time-derivative on object at current time: .
Generic class for numerical integration schemes:
Definition integral.h:49
virtual double knot(const unsigned &i, const unsigned &j) const =0
Return local coordinate s[j] of i-th integration point.
virtual unsigned nweight() const =0
Return the number of integration points of the scheme.
virtual double weight(const unsigned &i) const =0
Return weight of i-th integration point.
A class to specify when the error is caused by an inverted element.
Definition elements.h:5270
Nodes are derived from Data, but, in addition, have a definite (Eulerian) position in a space of a gi...
Definition nodes.h:906
TimeStepper *& position_time_stepper_pt()
Return a pointer to the position timestepper.
Definition nodes.h:1022
void perform_auxiliary_node_update_fct()
Execute auxiliary update function (if any) – this can be used to update any nodal values following th...
Definition nodes.h:1615
unsigned ndim() const
Return (Eulerian) spatial dimension of the node.
Definition nodes.h:1054
double & x(const unsigned &i)
Return the i-th nodal coordinate.
Definition nodes.h:1060
virtual void node_update(const bool &update_all_time_levels_for_new_node=false)
Interface for functions that update the nodal position using algebraic remeshing strategies....
Definition nodes.h:1586
double & x_gen(const unsigned &k, const unsigned &i)
Reference to the generalised position x(k,i). ‘Type’: k; Coordinate direction: i.
Definition nodes.h:1126
An OomphLibError object which should be thrown when an run-time error is encountered....
===================================================================== A class for handling oomph-lib ...
An OomphLibWarning object which should be created as a temporary object to issue a warning....
void shape(const Vector< double > &s, Shape &psi) const
Broken assignment operator.
Definition elements.cc:7556
static PointIntegral Default_integration_scheme
Return spatial dimension of element (=number of local coordinates needed to parametrise the element)
Definition elements.h:3477
Broken pseudo-integration scheme for points elements: Iit's not clear in general what this integratio...
Definition integral.h:89
A Class for shape functions. In simple cases, the shape functions have only one index that can be tho...
Definition shape.h:77
unsigned lagrangian_dimension() const
Return the number of Lagrangian coordinates that the element requires at all nodes....
Definition elements.h:3778
void describe_solid_local_dofs(std::ostream &out, const std::string &current_string) const
Classifies dofs locally for solid specific aspects.
Definition elements.cc:6901
double lagrangian_position_gen(const unsigned &n, const unsigned &k, const unsigned &i) const
Return Generalised Lagrangian coordinate at local node n. ‘Direction’ i, ‘Type’ k.
Definition elements.h:3916
double raw_lagrangian_position_gen(const unsigned &n, const unsigned &k, const unsigned &i) const
Return Generalised Lagrangian coordinate at local node n. ‘Direction’ i, ‘Type’ k....
Definition elements.h:3901
int * Position_local_eqn
Array to hold the local equation number information for the solid equations, whatever they may be.
Definition elements.h:4285
virtual void assemble_local_to_lagrangian_jacobian2(const DShape &d2psids, DenseMatrix< double > &jacobian2) const
Assemble the the "jacobian" matrix of second derivatives, given the second derivatives of the shape f...
Definition elements.cc:6613
virtual void assign_solid_local_eqn_numbers(const bool &store_local_dof)
Assigns local equation numbers for the generic solid local equation numbering schemes....
Definition elements.cc:6925
double dshape_lagrangian(const Vector< double > &s, Shape &psi, DShape &dpsidxi) const
Calculate shape functions and derivatives w.r.t. Lagrangian coordinates at local coordinate s....
Definition elements.cc:6737
unsigned nnodal_lagrangian_type() const
Return the number of types of (generalised) nodal Lagrangian coordinates required to interpolate the ...
Definition elements.h:3789
unsigned Lagrangian_dimension
The Lagrangian dimension of the nodes stored in the element, / i.e. the number of Lagrangian coordina...
Definition elements.h:4289
virtual void update_before_solid_position_fd()
Function that is called before the finite differencing of any solid position data....
Definition elements.h:4244
bool Solve_for_consistent_newmark_accel_flag
Flag to indicate which system of equations to solve when assigning initial conditions for time-depend...
Definition elements.h:4306
SolidInitialCondition * Solid_ic_pt
Pointer to object that specifies the initial condition.
Definition elements.h:4135
virtual double d2shape_lagrangian_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsidxi, DShape &d2psidxi) const
Return the geometric shape functions and also first and second derivatives w.r.t. Lagrangian coordina...
Definition elements.cc:6859
void fill_in_generic_jacobian_for_solid_ic(Vector< double > &residuals, DenseMatrix< double > &jacobian, const unsigned &flag)
Helper function to fill in the residuals and (if flag==1) the Jacobian for the setup of an initial co...
Definition elements.cc:7403
virtual double local_to_lagrangian_mapping_diagonal(const DShape &dpsids, DenseMatrix< double > &jacobian, DenseMatrix< double > &inverse_jacobian) const
Calculate the mapping from local to Lagrangian coordinates given the derivatives of the shape functio...
Definition elements.cc:6670
virtual void update_in_solid_position_fd(const unsigned &i)
Function called within the finite difference loop for the solid position dat after a change in any va...
Definition elements.h:4254
int position_local_eqn(const unsigned &n, const unsigned &k, const unsigned &j) const
Access function that returns the local equation number that corresponds to the j-th coordinate of the...
Definition elements.h:4141
virtual double local_to_lagrangian_mapping(const DShape &dpsids, DenseMatrix< double > &jacobian, DenseMatrix< double > &inverse_jacobian) const
Calculate the mapping from local to lagrangian coordinates, given the derivatives of the shape functi...
Definition elements.h:4086
virtual void assemble_local_to_lagrangian_jacobian(const DShape &dpsids, DenseMatrix< double > &jacobian) const
Assemble the jacobian matrix for the mapping from local to lagrangian coordinates,...
Definition elements.cc:6555
virtual double interpolated_xi(const Vector< double > &s, const unsigned &i) const
Return i-th FE-interpolated Lagrangian coordinate xi[i] at local coordinate s.
Definition elements.cc:7131
virtual void reset_in_solid_position_fd(const unsigned &i)
Function called within the finite difference loop for solid position data after the values in the i-t...
Definition elements.h:4259
virtual void interpolated_dxids(const Vector< double > &s, DenseMatrix< double > &dxids) const
Compute derivatives of FE-interpolated Lagrangian coordinates xi with respect to local coordinates: d...
Definition elements.cc:7207
virtual double dshape_lagrangian_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsidxi) const
Return the geometric shape functions and also first derivatives w.r.t. Lagrangian coordinates at ipt-...
Definition elements.cc:6764
virtual void fill_in_jacobian_from_solid_position_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Use finite differences to calculate the Jacobian entries corresponding to the solid positions....
Definition elements.cc:7012
double multiplier(const Vector< double > &xi)
Access to the "multiplier" for the inertia terms in the consistent determination of the initial condi...
Definition elements.h:4312
double d2shape_lagrangian(const Vector< double > &s, Shape &psi, DShape &dpsidxi, DShape &d2psidxi) const
Compute the geometric shape functions and also first and second derivatives w.r.t....
Definition elements.cc:6808
void compute_norm(double &el_norm)
Calculate the L2 norm of the displacement u=R-r to overload the compute_norm function in the Generali...
Definition elements.cc:6469
void describe_local_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the local dofs of the element. The ostream specifies the output stream to which ...
Definition elements.cc:6541
virtual ~SolidFiniteElement()
Destructor to clean up any allocated memory.
Definition elements.cc:6656
void fill_in_jacobian_for_newmark_accel(DenseMatrix< double > &jacobian)
Fill in the contributions of the Jacobian matrix for the consistent assignment of the initial "accele...
Definition elements.cc:7254
virtual void reset_after_solid_position_fd()
Function that is call after the finite differencing of the solid position data. This may be overloade...
Definition elements.h:4249
unsigned & ic_time_deriv()
Which time derivative are we currently assigning?
Definition elements.h:3521
GeomObject *& geom_object_pt()
(Reference to) pointer to geom object that specifies the initial condition
Definition elements.h:3515
A Class for nodes that deform elastically (i.e. position is an unknown in the problem)....
Definition nodes.h:1686
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
unsigned required_nvalue(const unsigned &n) const
Access function for Nvalue: # of ‘values’ (pinned or dofs) at node n (always returns the same value a...
Base class for time-stepping schemes. Timestepper provides an approximation of the temporal derivativ...
A slight extension to the standard template vector class so that we can include "graceful" array rang...
Definition Vector.h:58
unsigned Max_newton_iterations
Maximum number of newton iterations.
Definition elements.cc:1679
double Newton_tolerance
Convergence tolerance for the newton solver.
Definition elements.cc:1676
unsigned N_local_points
Number of points along one dimension of each element used to create coordinates within the element in...
Definition elements.cc:1690
double Radius_multiplier_for_fast_exit_from_locate_zeta
Multiplier for (zeta-based) outer radius of element used for deciding that point is outside element....
Definition elements.cc:1684
const double Pi
50 digits from maple
double dot(const Vector< double > &a, const Vector< double > &b)
Probably not always best/fastest because not optimised for dimension but useful...
Definition Vector.h:291
void cross(const Vector< double > &A, const Vector< double > &B, Vector< double > &C)
Cross product using "proper" output (move semantics means this is ok nowadays).
Definition Vector.h:319
double angle(const Vector< double > &a, const Vector< double > &b)
Get the angle between two vector.
Definition Vector.h:309
double magnitude(const Vector< double > &a)
Get the magnitude of a vector.
Definition Vector.h:303
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...