Marine systems simulation
|
You will need recent versions of the following tools:
gcc >= 8
or msvc++ >= 14.1
.Add the sintef-public
remote conan:
FhSim is installed and you are ready to start on your first project. Let's start out by looking at a tutorial project and how it works. The tutorial project models a spring, a cable and a point mass and creates a model based on an input file. This guide focuses on getting your source files up and running, not on how to write them.
The tutorial project can be found in XXX. It consists of two folders and some test files.
Item | Contents |
---|---|
build | Contains all files for configuring and installing. The compiler's project files will also end up in this folder. |
src | Contains all source files. This is also where you should add new ones. |
*.xml | Input files that demonstrate how to set up a simulation with the simobjects in the project. |
From the root directory, run the following commands: md build cd build cmake ../src -A x64
This should configure the project, creating the make files or the Visual Studio solution files, according to your platform and settings.
If you want to edit and compile the project from within your IDE, see Section Using an IDE. If you want to compile the project from the command line, see Section Compiling and installing from the command line.
Inside the build directory you will find the solution file (on Windows) or the make file (on Linux). For Windows, open the solution file in Visual Studio.
To compile the project from the command line, run the following command (after the configure step):
This will build and install both debug and release version of the library. The installation adds the library both to the playpen directory and the different SDK's.
Then go to the FhSimPlayPen_<COMPILER_SPEC>/bin
directory and run FhSim with the input file test3 with visualization on. Look in Section sec_fhsim_run_windows and sec_fhsim_run_linux for how to do this on Windows and Linux, respectively. The example input file is found in Examples of simple SimObjects.
../project/src/CMakeList.txt
holds the files that the script is looking for.CMakeCache.txt
before running the configuration again.Only the configure part is needed to get the project set up for editing and debugging in your IDE of choice. Open the solution file in your IDE, i.e. ../TutorialProject/build/TutorialProject.sln
for Visual Studio, and browse the project. You can now compile the project in your IDE. To debug we need to edit a few options and unfortunately there is no way to automate this with a CMake script. See debugging for more information.
The tutorial project initially consists of several source files, defining classes which are all simobjects. Amongst these classes are CMass and CSpring. The main difference between these are that the CMass contains states and has a very simple output function, while CSpring has no states but a more complex output function. In short, the following are the most important functions in a SimObject:
The constructor is responsible for reading the parameters belonging to the SimObject from the input file and defining the interface of the SimObject, in terms of:
This function is responsible for calculating the time derivative of the states of the SimObject. For the CMass object, this is done by setting the derivatives of the position equal to the velocity, and by setting the derivative of the velocity equal to the acceleration. The acceleration is found using Newton's laws.
Each output port is implemented as a method responsible for returning a pointer to the data structure containing the value of the output port.
One of the strengths of FhSim is the ability to combine different models to create new ones or big systems of different models. Models you have created for one type of problem might be reused to solve another. Lets try to modify the tutorial project by adding another SimObject. We could write new source code or we could link to existing libraries. Lets look at both of these options.
The FhSim shared library of projects consists of a number of different simobjects. Consult the documentation of FhSim libraries for a list of implemented simobjects. Sometimes there is no need to reinvent the wheel, sometimes you can just link to the libraries containing the source for the SimObject you need. All we have to do is add a few lines in CMakeLists.txt
file to tell the compiler that we want to link to that specific library. We add the following at appropriate places in CMakeLists.txt
(in the tutorial project this has already been done). See the CMake part of the FhSim guide for more about these files.
For simplicity we copy the CMass SimObject and rename it to create a new class called CMassNew
. Place this in the ../TutorialProject/src
folder among the other source files. Copying and modifying an existing source file is usually a good way to start as the structure of simobjects are often similar. Add the new file to the project by editing CMakeLists.txt
found in ../TutorialProject/src
(should also show up in your IDE). Add CMassNew.h
to the set(HEADER ...) line and CMassNew.cpp
to the set(SRC ...) line. Configure the project again and you are set to write your new source files. Let's keep it simple for now and just rename any instance of CMass to CMassNew, including the #ifndef
statement in the header file. When compiling the Tutorial Project, a library of the source files is made which is used when simulating. We need to add our new SimObject to the TutorialLib. Include the header file in SimObjectsLib.h
and a reference to the SimObject in SimObjectsLib.cpp
. Now we have a new SimObject, though the usefulness of many differently named, but otherwise equivalent objects can be debated. Install the project, and let's try testing it.
Each SimObject constructor takes as argument an instance of the class ISimObjectCreator
. This class handles the input files and the connection between different models as specified in the given input file. Load up the input file named test. For more information see the FhSim user's guide. If you remember from the first simulation of TutorialProject we had a spring with a big mass attached to it. Extending from the big mass was a cable with a smaller mass at the end. We now want to add a second cable from the smaller mass and attach a CMassNew SimObject in the end of it.
<OBJECTS>
, copy the input for the MassPointCable
named cable1
to create a new one called cable2 with the parameters of your choosing.<OBJECTS>
, copy the input for one of the Masses
and create a new one called mass2
with parameters of your choosing. Also change the SimObject parameter so that this input will be to an instance of your newly created MassNew
object.<OBJECTS>
, change the numInput
parameter of sum
from 2 to 3<Connection>
tag under <INTERCONNECTIONS>
, add the following attributes to make the new connections: <INITIALIZATION>
, set some initial conditions for the positions and velocity of mass2
.Instead of our new Mass object we could add the mass object with 6 degrees of freedom. This mass object has a few more ports so you have to change the input file slightly in order to simulate with visualization. Try doing that to see if you've understood how simobjects are declared and how they are connected. Hint: Modify the existing file, exchange one mass object with 6D mass. One possible solution:
The names and types of the parameters for each SimObject instance are not arbitrary, but specified in the implementation of the SimObject. They can be declared with a default value which will be used if no value is given in the input file. If no default value was declared, this would raise an error.
Save this input file as e.g. MyTest.xml
and try running the simulation with visualization. If you were successful, feel free to congratulate yourself. You have just created and visualized your first simobject!
Here follows an overview of repositories related to FhSim and their directory structure.
Repository | Availability | Directory | Contents |
---|---|---|---|
fhsim | Internal | The FhSim core project | |
fhsimbase | Open | Shared SimObjects and FhSim resources | |
sfhbase | Internal | Internal SimObjects and FhSim resources |
<project>/build
.INSTALL
project and choose Set as start-up project.C:/_work/FhSimPlayPen_<COMPILER_SPEC>/exe/FhVis_d
for visualization)<Absolute or relative path to input file>
)FhSimPlayPen_<COMPILER_SPEC>/exe
)<F5>
or by selecting Debug -> Start debugging.The default background colour appears to be black. In order to change the background colour of an animation, the following lines can be added to the RenderInit method of an object:
Ogre uses .mesh and .material files for 3D objects. This is a guideline for creating such models using a tool such as Solidworks.
.mesh.xml
fileOgreXmlConverter
tool to convert to .mesh
and .material
files.Table 2 (Synthetic Fiber Rope Properties) from http://www.tensiontech.com/papers/papers/deep_mor/synthetic_fibreyrope_table2.html. See also http://www.tensiontech.com/papers/papers/deep_mor/deep_mor.html.
Material | Rope construction | Strength kN/cm2 | Stiffness kN/cm2 | Remarks |
---|---|---|---|---|
Nylon | braided | 25 | 82 | Dry strengths only, wet strength 10-20% less |
Nylon | plaited | 20 | 87 | |
Polyester | braided | 25 | 210 | Wet and dry strengths, including jacket |
plaited | 20 | 160 | ||
7-strand | 45 | 400 | ||
parallel strand | 50 | 550 | ||
parallel fiber | 35 | 1000 | ||
Aramid | 36-strand | 70 | 3300 | Including jacket |
parallel strand | 65 | 2100 | ||
parallel fiber | 95 | 4300 | K29, including jacket | |
parallel fiber | 90 | 8000 | K49, including jacket | |
HMPE | braided | 55 | 1500 | Unjacketed |
7-strand | 55 | 2000 | Including jacket | |
parallel strand | 65 | 3000 | ||
Steel | 7-strand | 85 | 6800 | \[6 \times 36 \text{IWRC}\] |
bridge strand | 110 | 14000 | Not including jacket | |
Solid bar | 140 | 21000 | 4340 steel |
visualization
LogOutput.txt
(name and directory specified in the FhSim executable.Vis.dll
, .dll
or other extensions.Resources/Ogre.cfg
, to be able to specifyBuildAll.cmd
command in the $WORK/fhSim/Build directory
.When a simulation is started, the following process happens:
.dll
, the names are appended with:Vis
if visualization is enabled_d
if it is a debug build.dll
Any errors must be interpreted with this process in mind.
It is suggested to use CMake to create install targets or post-build events to copy the necessary binaries to the Playpen directory.
CMakeLists.txt
in the corresponding directory.CMakeLists.txt
.CMakeLists.txt
in Visual Studio for each project, found in the Solution Explorer.If you know the keystroke value of the special character you want to insert, you can insert the special character directly into your document by using your keyboard. To do so, open the document and position the cursor where you want the special character to appear. Then, with <NUM LOCK>
on, press and hold the <ALT>
key, and then press the keys on the numeric keypad that represent the keystroke value of the character you want to input. After you finish typing, release the <ALT>
key, and Windows generates the character you specified. NB! In Windows you need to include prepending zeros.
Example: With <NUM LOCK>
on and <ALT>
pressed, type at the numpad: "0169". This creates the copyright symbol ©.
ASCII codes can be found at for example:
This section contains some macros which can be used in Visual Studio to make the workflow more efficient. The macros include mostly functionality to:
To install these macros:
<alt> + F11
.<ctrl> + s
.Option Strict Off Option Explicit Off Imports System Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Imports Microsoft.VisualStudio.VCProjectEngine Public Module FormatDocs ' Shortcut: `[ctrl] + [alt] + d` ' Formats all open documents Sub FormatOpenDocuments() For i = 0 To DTE.Documents.Count() Try DTE.ExecuteCommand("Edit.SelectAll") DTE.ExecuteCommand("Edit.FormatSelection") DTE.ActiveDocument.Selection.StartOfDocument() DTE.ActiveDocument.Save() DTE.ExecuteCommand("Window.NextDocumentWindow") Catch End Try Next i End Sub Sub FormatDocument() ' Shortcut: `[ctrl] + [alt] + f` ' Formats the active document Try Dim selection As EnvDTE.TextSelection selection = DTE.ActiveDocument.Selection() ' Find the current position in the file Dim currentPoint As EnvDTE.EditPoint currentPoint = selection.TopPoint.CreateEditPoint() Dim line As Integer line = currentPoint.Line DTE.ExecuteCommand("Edit.SelectAll") DTE.ExecuteCommand("Edit.FormatSelection") DTE.ActiveDocument.Save() DTE.ActiveDocument.Selection.StartOfDocument() 'DTE.ActiveDocument.Selection.EndOfDocument() 'DTE.ActiveDocument.Selection.GotoLine(line - 30) DTE.ActiveDocument.Selection.GotoLine(line) 'DTE.ActiveDocument.Selection.GotoPoint(currentPoint) currentPoint.TryToShow(vsPaneShowHow.vsPaneShowCentered) Catch End Try End Sub Sub InsertHeaderClassComment() ' Shortcut: `[ctrl] + [alt] + 1` ' Inserts a Doxygen comment block in the header file DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// \class " DTE.ActiveDocument.Selection.Text = GetClassName() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "///" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// \brief " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// \author Karl-Johan Reite" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "///" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// <b>Copyright " Dim sel As TextSelection = DTE.ActiveDocument.Selection sel.Insert(Format(Date.Today, "yyyy")) DTE.ActiveDocument.Selection.Text = " by SINTEF Fisheries and Aquaculture</b>" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() End Sub Sub InsertSourceClassComment() ' Shortcut: `[ctrl] + [alt] + 2` ' Inserts a Doxygen comment block in the source file DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// \class " DTE.ActiveDocument.Selection.Text = GetClassName() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() End Sub Sub InsertSourceFunComment() ' Shortcut: `[ctrl] + [alt] + 3` ' Inserts a Doxygen comment before a source file function definition. ' If the function name is selected, this is used in the comments. Dim bHasCopied As Boolean Dim iSelectionLength = DTE.ActiveDocument.Selection.ToString.Length Dim objSel As TextSelection = DTE.ActiveDocument.Selection If Not objSel.IsEmpty Then 'If (iSelectionLength > 3) Then bHasCopied = True DTE.ActiveDocument.Selection.Copy() DTE.ActiveDocument.Selection.LineUp(False, 1) Else bHasCopied = False End If DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "//==================================================================================================" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "// FUNCTION NAME: " If (bHasCopied) Then DTE.ActiveDocument.Selection.Paste() End If DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "//==================================================================================================" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// \param [in] " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/// " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "////////////////////////////////////////////////////////////////////////////////////////////////////" End Sub Sub OpenPartnerFile() ' Shortcut: `[ctrl] + [alt] + s` ' Switches between the .cpp and .h file of the same name in the same folder. Dim filename As String Dim partnerFilename As String filename = DTE.ActiveDocument.FullName If (filename.EndsWith(".h")) Then partnerFilename = filename.Substring(0, filename.Length() - 2) + ".cpp" End If If (filename.EndsWith(".cpp")) Then partnerFilename = filename.Substring(0, filename.Length() - 4) + ".h" End If DTE.ItemOperations.OpenFile(partnerFilename) End Sub Sub LineSeparateParameterList() ' Shortcut: `[ctrl] + [alt] + p` ' If an argument list is selected, a new line is inserted after each comma. If (DTE.ActiveDocument.Selection.ToString().Length > 5) Then DTE.ExecuteCommand("Edit.Replace") DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.FindWhat = ", " DTE.Find.ReplaceWith = ",\n " DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection DTE.Find.MatchCase = True DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.Execute() DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close() End If End Sub Sub InsertForLoop3() ' Shortcut: `[ctrl] + [alt] + å` ' Creates a for-loop with an integer from 0 to -# If a ' name is selected, this is used as the index variable, ' otherwise "i" will be used. Dim sVariable As String Dim objSel As TextSelection = DTE.ActiveDocument.Selection If Not objSel.IsEmpty Then DTE.ActiveDocument.Selection.Copy() sVariable = objSel.Text Else sVariable = "i" End If DTE.ActiveDocument.Selection.Text = "for (int " DTE.ActiveDocument.Selection.Text = sVariable DTE.ActiveDocument.Selection.Text = " = 0; " DTE.ActiveDocument.Selection.Text = sVariable DTE.ActiveDocument.Selection.Text = " < 3; " DTE.ActiveDocument.Selection.Text = sVariable DTE.ActiveDocument.Selection.Text = "++) " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "{" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "}" End Sub Sub SetDebugoptions() ' Shortcut: `[ctrl] + [alt] + r` ' Sets the settings "Working directory" and "Command Arguments" under "Debugging" to an initial value. Dim prj As EnvDTE.Project Dim i, iNumProjects As Integer iNumProjects = DTE.Solution.Projects.Count For i = 1 To iNumProjects For j = 1 To DTE.Solution.Projects.Item(i).ConfigurationManager.Count DTE.Solution.Projects.Item(i).Object.Configurations.Item(1).DebugSettings.WorkingDirectory = "$(playpen)\\exe" DTE.Solution.Projects.Item(i).Object.Configurations.Item(1).DebugSettings.CommandArguments = "$(input)\\!test\\onemass" Next j Next i End Sub Function GetClassName() Dim filename As String Dim classname As String Dim iPoint As Integer Dim iLastSlash As Integer filename = DTE.ActiveDocument.FullName iPoint = filename.LastIndexOf(".") iLastSlash = filename.LastIndexOf("\") classname = filename.Substring(iLastSlash + 1, iPoint - iLastSlash - 1) Return classname End Function End Module
Download CMake from the CMake homepage. Remember to let CMake update the path info when you install it.
Install GuiTest
perl -MCPAN -e shell
cpan>force install Win32::GuiTest