equation_systems.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_EQUATION_SYSTEMS_H
21 #define LIBMESH_EQUATION_SYSTEMS_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/parameters.h"
26 #include "libmesh/system.h"
27 #include "libmesh/enum_xdr_mode.h"
29 
30 // HP aCC needs these for some reason
31 #ifdef __HP_aCC
34 # include "libmesh/newmark_system.h"
35 # include "libmesh/steady_system.h"
36 #endif
37 
38 // C++ includes
39 #include <cstddef>
40 #include <map>
41 #include <set>
42 #include <string>
43 #include <vector>
44 
45 namespace libMesh
46 {
47 
48 // Forward Declarations
49 class MeshData;
50 class Elem;
51 class MeshBase;
52 
66 // ------------------------------------------------------------
67 // EquationSystems class definition
68  class EquationSystems : public ReferenceCountedObject<EquationSystems>,
69  public ParallelObject
70 
71 {
72 public:
73 
77  enum ReadFlags { READ_HEADER = 1,
78  READ_DATA = 2,
83 
87  enum WriteFlags { WRITE_DATA = 1,
91 
95  EquationSystems (MeshBase& mesh, MeshData* mesh_data=NULL);
96 
101  virtual ~EquationSystems ();
102 
106  virtual void clear ();
107 
111  virtual void init ();
112 
116  virtual void reinit ();
117 
121  void update ();
122 
126  unsigned int n_systems() const;
127 
132  bool has_system (const std::string& name) const;
133 
140  template <typename T_sys>
141  const T_sys & get_system (const std::string& name) const;
142 
149  template <typename T_sys>
150  T_sys & get_system (const std::string& name);
151 
158  template <typename T_sys>
159  const T_sys & get_system (const unsigned int num) const;
160 
167  template <typename T_sys>
168  T_sys & get_system (const unsigned int num);
169 
173  const System & get_system (const std::string& name) const;
174 
178  System & get_system (const std::string& name);
179 
183  const System & get_system (const unsigned int num) const;
184 
188  System & get_system (const unsigned int num);
189 
194  virtual System & add_system (const std::string& system_type,
195  const std::string& name);
196 
200  template <typename T_sys>
201  T_sys & add_system (const std::string& name);
202 
208  void delete_system (const std::string& name);
209 
214  unsigned int n_vars () const;
215 
220  std::size_t n_dofs () const;
221 
226  std::size_t n_active_dofs() const;
227 
236  virtual void solve ();
237 
246  virtual void adjoint_solve (const QoISet& qoi_indices = QoISet());
247 
256  virtual void sensitivity_solve (const ParameterVector& parameters);
257 
265  void build_variable_names (std::vector<std::string>& var_names,
266  const FEType *type=NULL,
267  const std::set<std::string>* system_names=NULL) const;
268 
275  void build_solution_vector (std::vector<Number>& soln,
276  const std::string& system_name,
277  const std::string& variable_name = "all_vars") const;
278 
286  void build_solution_vector (std::vector<Number>& soln,
287  const std::set<std::string>* system_names=NULL) const;
288 
294  void get_solution( std::vector<Number> & soln,
295  std::vector<std::string> & names) const;
296 
302  void build_discontinuous_solution_vector (std::vector<Number>& soln) const;
303 
326  template <typename InValType>
327  void read (const std::string& name,
328  const libMeshEnums::XdrMODE,
329  const unsigned int read_flags=(READ_HEADER | READ_DATA),
330  bool partition_agnostic = true);
331 
332  void read (const std::string& name,
333  const libMeshEnums::XdrMODE mode,
334  const unsigned int read_flags=(READ_HEADER | READ_DATA),
335  bool partition_agnostic = true)
336  { read<Number>(name, mode, read_flags, partition_agnostic); }
337 
338  template <typename InValType>
339  void read (const std::string& name,
340  const unsigned int read_flags=(READ_HEADER | READ_DATA),
341  bool partition_agnostic = true);
342 
343  void read (const std::string& name,
344  const unsigned int read_flags=(READ_HEADER | READ_DATA),
345  bool partition_agnostic = true)
346  { read<Number>(name, read_flags, partition_agnostic); }
347 
348 
370  void write (const std::string& name,
371  const libMeshEnums::XdrMODE,
372  const unsigned int write_flags=(WRITE_DATA),
373  bool partition_agnostic = true) const;
374 
375  void write (const std::string& name,
376  const unsigned int write_flags=(WRITE_DATA),
377  bool partition_agnostic = true) const;
378 
385  virtual bool compare (const EquationSystems& other_es,
386  const Real threshold,
387  const bool verbose) const;
388 
393  virtual std::string get_info() const;
394 
399  void print_info (std::ostream& os=libMesh::out) const;
400 
404  friend std::ostream& operator << (std::ostream& os, const EquationSystems& es);
405 
409  const MeshBase & get_mesh() const;
410 
414  MeshBase & get_mesh();
415 
420  bool has_mesh_data() const;
421 
425  const MeshData & get_mesh_data() const;
426 
431 
436  void allgather ();
437 
438 
443 
444 
445 protected:
446 
447 
452 
458 
462  std::map<std::string, System*> _systems;
463 
467  typedef std::map<std::string, System*>::iterator system_iterator;
468 
472  typedef std::map<std::string, System*>::const_iterator const_system_iterator;
473 
474 private:
475 
486  template <typename InValType>
487  void _read_impl (const std::string& name,
488  const libMeshEnums::XdrMODE,
489  const unsigned int read_flags,
490  bool partition_agnostic = true);
491 
499 };
500 
501 
502 
503 // ------------------------------------------------------------
504 // EquationSystems inline methods
505 inline
507 {
508  return _mesh;
509 }
510 
511 
512 
513 inline
515 {
516  return _mesh;
517 }
518 
519 
520 inline
522 {
524  return *_mesh_data;
525 }
526 
527 
528 inline
530 {
532  return *_mesh_data;
533 }
534 
535 inline
537 {
538  return (_mesh_data!=NULL);
539 }
540 
541 
542 inline
543 unsigned int EquationSystems::n_systems () const
544 {
545  return libmesh_cast_int<unsigned int>(_systems.size());
546 }
547 
548 
549 
550 
551 template <typename T_sys>
552 inline
553 T_sys & EquationSystems::add_system (const std::string& name)
554 {
555  T_sys* ptr = NULL;
556 
557  if (!_systems.count(name))
558  {
559  ptr = new T_sys(*this, name, this->n_systems());
560 
561  _systems.insert (std::make_pair(name, ptr));
562 
563  // Tell all the \p DofObject entities to add a system.
565  }
566  else
567  {
568  // We now allow redundant add_system calls, to make it
569  // easier to load data from files for user-derived system
570  // subclasses
571 // libMesh::err << "ERROR: There was already a system"
572 // << " named " << name
573 // << std::endl;
574 
575 // libmesh_error();
576 
577  ptr = &(this->get_system<T_sys>(name));
578  }
579 
580  // Return a dynamically casted reference to the newly added System.
581  return *ptr;
582 }
583 
584 
585 
586 inline
587 bool EquationSystems::has_system (const std::string& name) const
588 {
589  if (_systems.find(name) == _systems.end())
590  return false;
591  return true;
592 }
593 
594 
595 
596 
597 template <typename T_sys>
598 inline
599 const T_sys & EquationSystems::get_system (const unsigned int num) const
600 {
601  libmesh_assert_less (num, this->n_systems());
602 
603 
604  const_system_iterator pos = _systems.begin();
605  const const_system_iterator end = _systems.end();
606 
607  for (; pos != end; ++pos)
608  if (pos->second->number() == num)
609  break;
610 
611  // Check for errors
612  if (pos == end)
613  {
614  libMesh::err << "ERROR: no system number " << num << " found!"
615  << std::endl;
616  libmesh_error();
617  }
618 
619  // Attempt dynamic cast
620  return *libmesh_cast_ptr<T_sys*>(pos->second);
621 }
622 
623 
624 
625 
626 template <typename T_sys>
627 inline
628 T_sys & EquationSystems::get_system (const unsigned int num)
629 {
630  libmesh_assert_less (num, this->n_systems());
631 
632  const_system_iterator pos = _systems.begin();
633  const const_system_iterator end = _systems.end();
634 
635  for (; pos != end; ++pos)
636  if (pos->second->number() == num)
637  break;
638 
639  // Check for errors
640  if (pos == end)
641  {
642  libMesh::err << "ERROR: no system number " << num << " found!"
643  << std::endl;
644  libmesh_error();
645  }
646 
647  // Attempt dynamic cast
648  return *libmesh_cast_ptr<T_sys*>(pos->second);
649 }
650 
651 
652 
653 
654 
655 
656 template <typename T_sys>
657 inline
658 const T_sys & EquationSystems::get_system (const std::string& name) const
659 {
660  const_system_iterator pos = _systems.find(name);
661 
662  // Check for errors
663  if (pos == _systems.end())
664  {
665  libMesh::err << "ERROR: no system named \"" << name << "\" found!"
666  << std::endl;
667  libmesh_error();
668  }
669 
670  // Attempt dynamic cast
671  return *libmesh_cast_ptr<T_sys*>(pos->second);
672 }
673 
674 
675 
676 
677 
678 
679 template <typename T_sys>
680 inline
681 T_sys & EquationSystems::get_system (const std::string& name)
682 {
683  system_iterator pos = _systems.find(name);
684 
685  // Check for errors
686  if (pos == _systems.end())
687  {
688  libMesh::err << "ERROR: no system named " << name << " found!"
689  << std::endl;
690  libmesh_error();
691  }
692 
693  // Attempt dynamic cast
694  return *libmesh_cast_ptr<T_sys*>(pos->second);
695 }
696 
697 
698 
699 
700 
701 
702 
703 inline
704 const System & EquationSystems::get_system (const std::string& name) const
705 {
706  return this->get_system<System>(name);
707 }
708 
709 
710 
711 inline
712 System & EquationSystems::get_system (const std::string& name)
713 {
714  return this->get_system<System>(name);
715 }
716 
717 
718 
719 inline
720 const System & EquationSystems::get_system (const unsigned int num) const
721 {
722  return this->get_system<System>(num);
723 }
724 
725 
726 
727 inline
728 System & EquationSystems::get_system (const unsigned int num)
729 {
730  return this->get_system<System>(num);
731 }
732 
733 
734 } // namespace libMesh
735 
736 
737 #endif // LIBMESH_EQUATION_SYSTEMS_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:04 UTC

Hosted By:
SourceForge.net Logo