LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
example_rhs.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014, Sam Schetterer, Nathan Kutz, University of Washington
3 Authors: Sam Schetterer
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11 
12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 
16 */
18 
25 #include "rhs_type.hpp"//This file contains the template for the base class type, along with most basic headers
26 //The way this works is through polymorphism, which basically means that the engine sees a class of rhs, but is really accessing a class of type example_rhs
27 
28 
30 
38 class example_rhs:public rhs_type<comp>{
39  //up here declare variables that are used internally by the function
40  //These may be akin to various parameters, tunable or not
41 
42  //double represents the 64 bit floating point variables
43  double val1, val2;
44 
45  //std::string represents the string type values
47 
48  //comp values are the complex variable types
49  //comp_funcs.h contains some optimized functions for manipulating complex variables
51 
52  //pointers store a location in memory, and can act as arrays.
53  //They offer high performance compared to other options,but also require
54  //rather vigilant care since they directly manipulate memory
55  //They are useful for storing temporary calculations
57 
58  public: //anything that isn't declared under public is only accessible through
59  //functions of the class, but public members can be accessed outside of the class
60  //
61  //Functions of a c++ class are declared in a header file, but actually defined in a source file
62  //This allows one to separate the implementation of the class from telling the engine
63  //what the class is, ane makes everything work better in the long run
64  //
65  //PLEASE FOLLOW THIS PATTERN WITH USER DEFINIED CLASSES
66  //
67  //these functions delcared in the next block are utility functions
68  //used by the engine to sort different parts of the simulation and
69  //make everything work nicely together. In each class they must be declared exactly
70  //as is here. The detailed documentation, and comments in the .cpp file,
71  //have information on what these functions do
72 
73  virtual std::string type() const;
74  virtual std::vector<std::string> dependencies() const;
75  virtual void postprocess(input& indat);
76 
77 
78  //This function updates data inside the class whenever a variable it references changes
79  //use it to re-do any calculations that are done to initialize the class
80  virtual void update();
81 
82  //This function calculates the derivative given the current function value
83  //Note that instead of pointers, this class takes in an object of type
84  //ptr_passer. This holds a pointer and type information to ensure that
85  //the rest of the engine, which is quite generic and type-independent,
86  //won't pass the wrong type of pointer to this function. Although the
87  //rest of the type-checking is probably strict enough to allow the use of
88  //void*, this prevents a user from accidentally passing a bad pointer anyways.
89  virtual int dxdt(ptr_passer x, ptr_passer dx, double t);
90 
91  //This is a destructor, which frees all of your memory
92  //if you allocate any memory, you must free it
93  virtual ~example_rhs();
94 };
95