MoorDyn
Instance.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022, Matt Hall
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
36 #pragma once
37 
38 #include "Misc.hpp"
39 #include "IO.hpp"
40 #include "Log.hpp"
41 #include <utility>
42 
43 namespace moordyn {
44 
45 class Waves;
46 typedef std::shared_ptr<Waves> WavesRef;
47 
48 class Point;
49 class Rod;
50 
54 class DECLDIR Instance : public io::IO
55 {
56  public:
60  Instance(moordyn::Log* log);
61 
64  virtual ~Instance() = default;
65 
76  inline const size_t id() const { return _id; }
77 
83  virtual void initialize(InstanceStateVarView r) = 0;
84 
88  virtual void setState(const InstanceStateVarView r) = 0;
89 
94  virtual void getStateDeriv(InstanceStateVarView drdt) = 0;
95 
101  virtual inline const size_t stateN() const { return 1; }
102 
108  virtual inline const size_t stateDims() const { return 6; }
109 
110  private:
112  size_t _id;
113 };
114 
118 void
120 
121 } // ::moordyn
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition: MoorDynAPI.h:68
A generic instance.
Definition: Instance.hpp:55
virtual const size_t stateN() const
Get the number of state variables required by this instance.
Definition: Instance.hpp:101
const size_t id() const
Get the unique identifier of this instance.
Definition: Instance.hpp:76
virtual const size_t stateDims() const
Get the dimension of the state variable.
Definition: Instance.hpp:108
virtual void initialize(InstanceStateVarView r)=0
Initialize a free instance.
virtual void getStateDeriv(InstanceStateVarView drdt)=0
Calculate forces and get the derivative of the states.
virtual void setState(const InstanceStateVarView r)=0
Set the state.
virtual ~Instance()=default
Destructor.
A Logging utility.
Definition: Log.hpp:149
A base class for all the entities that must save/load data to/from disk.
Definition: IO.hpp:60
MoorDyn2 C++ API namespace.
Definition: Body.cpp:27
std::shared_ptr< Waves > WavesRef
Definition: Body.hpp:53
Eigen::Block< InstanceStateVar, Eigen::Dynamic > InstanceStateVarView
View of the State variables for a particular instance.
Definition: Misc.hpp:167
void reset_instance_ids()
Reset the instances Ids, so they will be assigned again starting from 0.
Definition: Instance.cpp:32