equation_systems.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_EQUATION_SYSTEMS_H 00021 #define LIBMESH_EQUATION_SYSTEMS_H 00022 00023 // Local Includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/parameters.h" 00026 #include "libmesh/system.h" 00027 #include "libmesh/enum_xdr_mode.h" 00028 00029 // HP aCC needs these for some reason 00030 #ifdef __HP_aCC 00031 # include "libmesh/frequency_system.h" 00032 # include "libmesh/transient_system.h" 00033 # include "libmesh/newmark_system.h" 00034 # include "libmesh/steady_system.h" 00035 #endif 00036 00037 // C++ includes 00038 #include <cstddef> 00039 #include <map> 00040 #include <set> 00041 #include <string> 00042 #include <vector> 00043 00044 namespace libMesh 00045 { 00046 00047 // Forward Declarations 00048 class MeshData; 00049 class Elem; 00050 class MeshBase; 00051 00065 // ------------------------------------------------------------ 00066 // EquationSystems class definition 00067 class EquationSystems : public ReferenceCountedObject<EquationSystems> 00068 { 00069 public: 00070 00074 enum ReadFlags { READ_HEADER = 1, 00075 READ_DATA = 2, 00076 READ_ADDITIONAL_DATA = 4, 00077 READ_LEGACY_FORMAT = 8, 00078 TRY_READ_IFEMS = 16, 00079 READ_BASIC_ONLY = 32 }; 00080 00084 enum WriteFlags { WRITE_DATA = 1, 00085 WRITE_ADDITIONAL_DATA = 2, 00086 WRITE_PARALLEL_FILES = 4, 00087 WRITE_SERIAL_FILES = 8 }; 00088 00092 EquationSystems (MeshBase& mesh, MeshData* mesh_data=NULL); 00093 00098 virtual ~EquationSystems (); 00099 00103 virtual void clear (); 00104 00108 virtual void init (); 00109 00113 virtual void reinit (); 00114 00118 void update (); 00119 00123 unsigned int n_systems() const; 00124 00129 bool has_system (const std::string& name) const; 00130 00137 template <typename T_sys> 00138 const T_sys & get_system (const std::string& name) const; 00139 00146 template <typename T_sys> 00147 T_sys & get_system (const std::string& name); 00148 00155 template <typename T_sys> 00156 const T_sys & get_system (const unsigned int num) const; 00157 00164 template <typename T_sys> 00165 T_sys & get_system (const unsigned int num); 00166 00170 const System & get_system (const std::string& name) const; 00171 00175 System & get_system (const std::string& name); 00176 00180 const System & get_system (const unsigned int num) const; 00181 00185 System & get_system (const unsigned int num); 00186 00191 virtual System & add_system (const std::string& system_type, 00192 const std::string& name); 00193 00197 template <typename T_sys> 00198 T_sys & add_system (const std::string& name); 00199 00205 void delete_system (const std::string& name); 00206 00211 unsigned int n_vars () const; 00212 00217 std::size_t n_dofs () const; 00218 00223 std::size_t n_active_dofs() const; 00224 00233 virtual void solve (); 00234 00243 virtual void adjoint_solve (const QoISet& qoi_indices = QoISet()); 00244 00253 virtual void sensitivity_solve (const ParameterVector& parameters); 00254 00262 void build_variable_names (std::vector<std::string>& var_names, 00263 const FEType *type=NULL, 00264 const std::set<std::string>* system_names=NULL) const; 00265 00272 void build_solution_vector (std::vector<Number>& soln, 00273 const std::string& system_name, 00274 const std::string& variable_name = "all_vars") const; 00275 00283 void build_solution_vector (std::vector<Number>& soln, 00284 const std::set<std::string>* system_names=NULL) const; 00285 00291 void get_solution( std::vector<Number> & soln, 00292 std::vector<std::string> & names) const; 00293 00299 void build_discontinuous_solution_vector (std::vector<Number>& soln) const; 00300 00317 void read (const std::string& name, 00318 const libMeshEnums::XdrMODE, 00319 const unsigned int read_flags=(READ_HEADER | READ_DATA)); 00320 00321 void read (const std::string& name, 00322 const unsigned int read_flags=(READ_HEADER | READ_DATA)); 00323 00339 void write (const std::string& name, 00340 const libMeshEnums::XdrMODE, 00341 const unsigned int write_flags=(WRITE_DATA)) const; 00342 00343 void write (const std::string& name, 00344 const unsigned int write_flags=(WRITE_DATA)) const; 00345 00352 virtual bool compare (const EquationSystems& other_es, 00353 const Real threshold, 00354 const bool verbose) const; 00355 00360 virtual std::string get_info() const; 00361 00366 void print_info (std::ostream& os=libMesh::out) const; 00367 00371 friend std::ostream& operator << (std::ostream& os, const EquationSystems& es); 00372 00376 const MeshBase & get_mesh() const; 00377 00381 MeshBase & get_mesh(); 00382 00387 bool has_mesh_data() const; 00388 00392 const MeshData & get_mesh_data() const; 00393 00397 MeshData & get_mesh_data(); 00398 00403 void allgather (); 00404 00405 00409 Parameters parameters; 00410 00411 00412 protected: 00413 00414 00418 MeshBase& _mesh; 00419 00424 MeshData* _mesh_data; 00425 00429 std::map<std::string, System*> _systems; 00430 00434 typedef std::map<std::string, System*>::iterator system_iterator; 00435 00439 typedef std::map<std::string, System*>::const_iterator const_system_iterator; 00440 00441 private: 00442 00447 void _read_impl (const std::string& name, 00448 const libMeshEnums::XdrMODE, 00449 const unsigned int read_flags); 00450 00457 void _add_system_to_nodes_and_elems(); 00458 }; 00459 00460 00461 00462 // ------------------------------------------------------------ 00463 // EquationSystems inline methods 00464 inline 00465 const MeshBase & EquationSystems::get_mesh () const 00466 { 00467 return _mesh; 00468 } 00469 00470 00471 00472 inline 00473 MeshBase & EquationSystems::get_mesh () 00474 { 00475 return _mesh; 00476 } 00477 00478 00479 inline 00480 const MeshData & EquationSystems::get_mesh_data () const 00481 { 00482 libmesh_assert(_mesh_data); 00483 return *_mesh_data; 00484 } 00485 00486 00487 inline 00488 MeshData & EquationSystems::get_mesh_data () 00489 { 00490 libmesh_assert(_mesh_data); 00491 return *_mesh_data; 00492 } 00493 00494 inline 00495 bool EquationSystems::has_mesh_data () const 00496 { 00497 return (_mesh_data!=NULL); 00498 } 00499 00500 00501 inline 00502 unsigned int EquationSystems::n_systems () const 00503 { 00504 return libmesh_cast_int<unsigned int>(_systems.size()); 00505 } 00506 00507 00508 00509 00510 template <typename T_sys> 00511 inline 00512 T_sys & EquationSystems::add_system (const std::string& name) 00513 { 00514 T_sys* ptr = NULL; 00515 00516 if (!_systems.count(name)) 00517 { 00518 ptr = new T_sys(*this, name, this->n_systems()); 00519 00520 _systems.insert (std::make_pair(name, ptr)); 00521 00522 // Tell all the \p DofObject entities to add a system. 00523 this->_add_system_to_nodes_and_elems(); 00524 } 00525 else 00526 { 00527 // We now allow redundant add_system calls, to make it 00528 // easier to load data from files for user-derived system 00529 // subclasses 00530 // libMesh::err << "ERROR: There was already a system" 00531 // << " named " << name 00532 // << std::endl; 00533 00534 // libmesh_error(); 00535 00536 ptr = &(this->get_system<T_sys>(name)); 00537 } 00538 00539 // Return a dynamically casted reference to the newly added System. 00540 return *ptr; 00541 } 00542 00543 00544 00545 inline 00546 bool EquationSystems::has_system (const std::string& name) const 00547 { 00548 if (_systems.find(name) == _systems.end()) 00549 return false; 00550 return true; 00551 } 00552 00553 00554 00555 00556 template <typename T_sys> 00557 inline 00558 const T_sys & EquationSystems::get_system (const unsigned int num) const 00559 { 00560 libmesh_assert_less (num, this->n_systems()); 00561 00562 00563 const_system_iterator pos = _systems.begin(); 00564 const const_system_iterator end = _systems.end(); 00565 00566 for (; pos != end; ++pos) 00567 if (pos->second->number() == num) 00568 break; 00569 00570 // Check for errors 00571 if (pos == end) 00572 { 00573 libMesh::err << "ERROR: no system number " << num << " found!" 00574 << std::endl; 00575 libmesh_error(); 00576 } 00577 00578 // Attempt dynamic cast 00579 return *libmesh_cast_ptr<T_sys*>(pos->second); 00580 } 00581 00582 00583 00584 00585 template <typename T_sys> 00586 inline 00587 T_sys & EquationSystems::get_system (const unsigned int num) 00588 { 00589 libmesh_assert_less (num, this->n_systems()); 00590 00591 const_system_iterator pos = _systems.begin(); 00592 const const_system_iterator end = _systems.end(); 00593 00594 for (; pos != end; ++pos) 00595 if (pos->second->number() == num) 00596 break; 00597 00598 // Check for errors 00599 if (pos == end) 00600 { 00601 libMesh::err << "ERROR: no system number " << num << " found!" 00602 << std::endl; 00603 libmesh_error(); 00604 } 00605 00606 // Attempt dynamic cast 00607 return *libmesh_cast_ptr<T_sys*>(pos->second); 00608 } 00609 00610 00611 00612 00613 00614 00615 template <typename T_sys> 00616 inline 00617 const T_sys & EquationSystems::get_system (const std::string& name) const 00618 { 00619 const_system_iterator pos = _systems.find(name); 00620 00621 // Check for errors 00622 if (pos == _systems.end()) 00623 { 00624 libMesh::err << "ERROR: no system named \"" << name << "\" found!" 00625 << std::endl; 00626 libmesh_error(); 00627 } 00628 00629 // Attempt dynamic cast 00630 return *libmesh_cast_ptr<T_sys*>(pos->second); 00631 } 00632 00633 00634 00635 00636 00637 00638 template <typename T_sys> 00639 inline 00640 T_sys & EquationSystems::get_system (const std::string& name) 00641 { 00642 system_iterator pos = _systems.find(name); 00643 00644 // Check for errors 00645 if (pos == _systems.end()) 00646 { 00647 libMesh::err << "ERROR: no system named " << name << " found!" 00648 << std::endl; 00649 libmesh_error(); 00650 } 00651 00652 // Attempt dynamic cast 00653 return *libmesh_cast_ptr<T_sys*>(pos->second); 00654 } 00655 00656 00657 00658 00659 00660 00661 00662 inline 00663 const System & EquationSystems::get_system (const std::string& name) const 00664 { 00665 return this->get_system<System>(name); 00666 } 00667 00668 00669 00670 inline 00671 System & EquationSystems::get_system (const std::string& name) 00672 { 00673 return this->get_system<System>(name); 00674 } 00675 00676 00677 00678 inline 00679 const System & EquationSystems::get_system (const unsigned int num) const 00680 { 00681 return this->get_system<System>(num); 00682 } 00683 00684 00685 00686 inline 00687 System & EquationSystems::get_system (const unsigned int num) 00688 { 00689 return this->get_system<System>(num); 00690 } 00691 00692 00693 } // namespace libMesh 00694 00695 00696 #endif // LIBMESH_EQUATION_SYSTEMS_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:46 UTC
Hosted By: