1 / 24

Object-Oriented Design Patterns for Multiphysics Modeling in Fortran 2003 and C++

Object-Oriented Design Patterns for Multiphysics Modeling in Fortran 2003 and C++. Damian Rouson, Helgi Adalssteinson Scalable Computing R&D Sandia National Laboratories. Jim Xia XL Fortran Compiler Test IBM. Sponsor: Office of Naval Research.

dean
Télécharger la présentation

Object-Oriented Design Patterns for Multiphysics Modeling in Fortran 2003 and C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object-Oriented Design Patterns for Multiphysics Modeling in Fortran 2003 and C++ Damian Rouson, Helgi Adalssteinson Scalable Computing R&D Sandia National Laboratories Jim Xia XL Fortran Compiler Test IBM Sponsor: Office of Naval Research Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,for the United States Department of Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000.

  2. Roadmap • Motivation, objectives & previous work • Design patterns essentials & terminology • Patterns for multiphysics • Language comparison • Conclusions

  3. Motivation • Availability of OOP constructs in Fortran 2003 • Shortage meso-scale scientific software architecture discussions: “Today it is altogether too difficult to develop computational science software and applications. Environments and toolkits are inadequate to meet the needs of software developers in addressing increasingly complex interdisciplinary [applications]… In addition, since there is no consistency in software engineering best practices, many of the new applications are not robust and cannot easily be ported to new hardware.” Presidential Information Technology Advisory Committee (1999) [cited by NSF Blue Ribbon Panel in 2006]

  4. Objectives • Develop an analysis-driven approach to writing interdisciplinary scientific software • Abstract from the resulting software a set of design patterns • Compare Fortran 2003 & C++ implementations

  5. Previous Work • General Design Patterns • Alexander 1977: architecture • Gamma et al. 1994: software • Scientific application of general patterns: • Markus (2007): Fortran 95 • Gardner & Manduchi (2007): Java • Gardner & Decyk (2008): Fortran 95 • Scientific domain-specific patterns: • Blilie (2003): grid, particle, etc. • Mattson et al. (2004): parallel computing • Rouson and Xia (2008): multiphysics

  6. Outline • Motivation, objectives & previous work • Design patterns essentials & terminology • Patterns for multiphysics • Language comparison • Conclusions

  7. Essential Elements of a Pattern • The name • For example, the Mediator Pattern • The problem • 2N(N-1) connections between communicating objects • The solution • Transmit all messages via a mediator • The consequences • Only 2N connections • Two-way associations

  8. Rosetta Stone *Unified Modeling Language (UML)

  9. Outline • Motivation, objectives & previous work • Design patterns essentials & terminology • Patterns for multiphysics • Prototype: Lorenz equations • Analysis • The patterns & true multiphysics • Language comparison • Conclusions

  10. Multiphysics Prototype Coupled PDE’s: Boundary conditions: Initial conditions: Semi-discrete approach: Lorenz equations:

  11. Analysis • Amdahl’s law limits speedup strategies that focus strictly on runtime* • Inheritance and polymorphism attack problems that scale linearly with the size of the code; whereas Encapsulation and Information Hiding attack a problem that scales quadratically** • Encapsulating data & procedures in mathematical classes (that support overloaded expressions) renders the quadratic metric constant* *Rouson et al. (2008) ACM Trans. Math. Soft. **Rouson & Xiong (2004) Scientific Programming

  12. The Semi-Discrete Pattern • Legend • Inheritance • + Public behavior • - Private state

  13. Semi-Discrete Pattern in Fortran 2003 Explicit Euler time advancment: Polymorphic integration procedure: subroutine integrate(this,dt) class(integrable_model) :: this real ,intent(in) :: dt end subroutine integrate Consequences: high cohesion, low coupling this = this + d_dt(this)*dt

  14. The Strategy Pattern “Find what varies and encapsulate it.” Shalloway & Troutt, Design Patterns Explained, 2003 integrable_model strategy • Legend • Inheritance • Association lorenz explicit_euler runge_kutta2 timed_lorenz

  15. The Surrogate Pattern surrogate integrable_model strategy • Legend • Inheritance • Association lorenz explicit_euler runge_kutta2 timed_lorenz

  16. The Puppeteer Pattern • Legend • Aggregation Puppeteer roles: Mediate inter-object communications Construct partial derivative terms in Jacobian for implicit time advancement: Consequence: reduce couplings from 2N to N

  17. The Template Class Pattern: Morfeus integrable_model • Legend • Inheritance • Composition • Aggregation Puppeteer Quantum Fluid Classical Fluid Scalar Cloud Magnetofluid Fourier Field - basis_set : Template$ - nodes : Grid Template$ FourierChebyshev Cartesian Grid - nodal_locations : Template$ Cosine

  18. Outline • Motivation, objectives & previous work • Design patterns essentials & terminology • Patterns for multiphysics • Language comparison • The big picture • Code examples • Conclusions

  19. Language Comparison C++ features we emulated in Fortran 2003 • Forward references (surrogate) • Templates (macro) Fortran 2003 features we emulated in C++ • Automatic array allocation/de-allocation (N.A.) • Multi-dimensional arrays & array descriptors (typedef struct{ float* x,int shape[2]}arr;) • Array semantics (N.A.) • Dynamic type safety (try/catch+dynamic_cast) • Module scope/lifetime (macro+namespace)

  20. Abstract Derived Type (PureVirtualClass) module integrable_model_module … type, abstract, public :: integrable_model contains procedure(symmetric_operator), deferred :: add generic :: operator(+) => add … end type integrable_model abstract interface function symmetric_operator(lhs,rhs) result(opResult) import :: integrable_model class(integrable_model),intent(in) :: lhs,rhs class(integrable_model),allocatable :: opResult end function symmetric_operator end abstract interface

  21. Type Extension (Inheritance) module lorenz_module use integrable_model_module … type, extends(integrable_model), public :: lorenz private real,dimension(:),allocatable::state !solution vector contains procedure :: lorenz ! constructor procedure :: d_dt => dLorenz_dt procedure :: add => add_lorenz procedure :: multiply => multiply_lorenz procedure :: assign => assign_lorenz end type lorenz …

  22. Defined (Overloaded) Operator function add_Lorenz(lhs,rhs) result(sum) class(lorenz) ,intent(in) :: lhs class(integrable_model) ,intent(in) :: rhs class(integrable_model) ,allocatable :: sum select type(lhs) type is (lorenz) allocate(lorenz :: sum) select type(sum) type is (lorenz) !allocate(sum%state(size(lhs%state))) select type(rhs) type is (lorenz) sum%state = lhs%state + rhs%state end select end select end select

  23. C++ Addition Function integrable_model* lorenz::add (const integrable_model* rhs) const { lorenz* result; float* state_array;const lorenz* RHS; state_array = new float[_size]; result = new lorenz; try {RHS = dynamic_cast<const lorenz *>(rhs);} catch(exception & e) {cerr << "lorenz::add, type casting failed" << endl; exit(1);} for (int i = 0; i < _size; ++i) {state_array[i] = _state[i] + RHS->_state[i];} result->set_coordinate(state_array, _size); delete [] state_array; return result; }

  24. Conclusions • The presented patterns integrate multiple abstractions, allowing much of the numerics and physics to be determined at compile-time or runtime • Negligible lines of Fortran emulate the required C++ features • C++ requires greater effort (or greater reliance on libraries to relieve that effort) to emulate the required Fortran 2003 features

More Related