-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add FMU participants to oscillator tutorial #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
4c92b98
Add FMU example. Exchanged data switches from 'Force' to 'Displacement'.
42884c1
Update README
d7fee6c
Update README.md
LeonardWilleke 8209447
Use Oscillator.fmu and force-force exchange
a4ee334
Adapt README.md
d32e15e
Adapt README.md
bf5b8aa
Minor changes to runner.py
fce783e
Update FMU model and README.md
a70d411
Update make files to allow compilation as FMI 1, 2 and 3
2b3157f
Implement requested changes
9849995
Adapt case to use fmiprecice instead of local runner script
f17125e
Update License and README, do cosmetic changes on code
9a22c67
Adapt makefile to include LICENSE in FMU
8ab4529
Update Python oscillator to precice v3
0fd3bd9
Add link to reference
3db4327
Merge branch 'develop' into create-fmu-oscillator-v3
uekerman 2e9f61d
Use python oscillator from develop
uekerman 11072ae
Adjust precice-settings.json to v3 runner
uekerman 35d6adb
Tweak README
uekerman a1d38be
Make pre-commit work for Ubuntu 20.04
uekerman 2f05209
Make md linter happy
uekerman ef0ea11
Format all FMI xml files
uekerman c892903
Format code
uekerman cb5137d
Format code
uekerman fba9c9a
Merge branch 'develop' into create-fmu-oscillator-v3
MakisH 98adffd
Update oscillator/README.md
MakisH 2e57756
Oscillator: Move license
MakisH 53b8c5c
Update link to license in CMakeLists.txt
MakisH 47b0904
Remove binary FMU, replace with automatic building in run
uekerman 960a588
Format all FMU C code
uekerman 558fac4
Remove duplicate FMU readme.html
MakisH 94ba065
Merge branch 'develop' into create-fmu-oscillator-v3
MakisH 1f9a2b4
Add FMU readme.html again
MakisH e5e8e5d
Delete duplicate FMU readme.md
MakisH 4517bbd
Change causality of mass.a to local, fix CATIA bug
uekerman af91d46
Fix spelling of state attributes in FMI3
uekerman 11cc439
Remove FMI1 config files
uekerman 99d3c8a
Switch to FMI3 again
uekerman 6a57614
Increase accuracy of material params and initial cond
uekerman e29dd45
Merge branch 'develop' into create-fmu-oscillator-v3
MakisH 945836a
Remove more FMI1 things
uekerman 39272a8
Merge branch 'develop' into create-fmu-oscillator-v3
MakisH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fmi/Oscillator.fmu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"model_params": { | ||
"mass.m": 1, | ||
"spring_fixed.c": 39.4784176044, | ||
"spring_middle.c": 157.913670417 | ||
}, | ||
"initial_conditions": { | ||
"mass.u": 1, | ||
"mass.v": 0, | ||
"mass.a": -197.392088022 | ||
}, | ||
"simulation_params": { | ||
"fmu_file_name": "./Oscillator.fmu", | ||
"output_file_name": "./output/trajectory-Mass-Left.csv", | ||
"output": ["mass.u", "mass.v"], | ||
"fmu_read_data_names": ["force_in"], | ||
"fmu_write_data_names": ["force_out"], | ||
"fmu_instance_name": "instance_left" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"coupling_params": { | ||
"participant_name": "Mass-Left", | ||
"config_file_name": "../precice-config.xml", | ||
"mesh_name": "Mass-Left-Mesh", | ||
"write_data_name": "Force-Left", | ||
"read_data_name": "Force-Right" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"model_params": { | ||
"mass.m": 1, | ||
"spring_fixed.c": 39.4784176044, | ||
"spring_middle.c": 157.913670417 | ||
}, | ||
"initial_conditions": { | ||
"mass.u": 0, | ||
"mass.v": 0, | ||
"mass.a": 157.913670417 | ||
}, | ||
"simulation_params": { | ||
"fmu_file_name": "./Oscillator.fmu", | ||
"output_file_name": "./output/trajectory-Mass-Right.csv", | ||
"output": ["mass.u", "mass.v"], | ||
"fmu_read_data_names": ["force_in"], | ||
"fmu_write_data_names": ["force_out"], | ||
"fmu_instance_name": "instance_right" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"coupling_params": { | ||
"participant_name": "Mass-Right", | ||
"config_file_name": "../precice-config.xml", | ||
"mesh_name": "Mass-Right-Mesh", | ||
"write_data_name": "Force-Right", | ||
"read_data_name": "Force-Left" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import json | ||
import os | ||
import argparse | ||
from enum import Enum | ||
import sys | ||
|
||
|
||
class Participant(Enum): | ||
MASS_LEFT = "Mass-Left" | ||
MASS_RIGHT = "Mass-Right" | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("fmi_setting_file_left", help="Path to the fmi setting file for MassLeft.", type=str) | ||
parser.add_argument("precice_setting_file_left", help="Path to the precice setting file for MassLeft.", type=str) | ||
parser.add_argument("fmi_setting_file_right", help="Path to the fmi setting file for MassRight.", type=str) | ||
parser.add_argument("precice_setting_file_right", help="Path to the precice setting file for MassRight.", type=str) | ||
parser.add_argument("participant_name", help="Participant for which the error should be calculated", type=str, | ||
choices=[p.value for p in Participant]) | ||
args = parser.parse_args() | ||
|
||
# Get input files | ||
fmi_file_left = args.fmi_setting_file_left | ||
precice_file_left = args.precice_setting_file_left | ||
fmi_file_right = args.fmi_setting_file_right | ||
precice_file_right = args.precice_setting_file_right | ||
participant_name = args.participant_name | ||
|
||
# Read json files | ||
folder = os.path.dirname(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), fmi_file_left)) | ||
path = os.path.join(folder, os.path.basename(fmi_file_left)) | ||
read_file = open(path, "r") | ||
fmi_data_left = json.load(read_file) | ||
|
||
folder = os.path.dirname(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), precice_file_left)) | ||
path = os.path.join(folder, os.path.basename(precice_file_left)) | ||
read_file = open(path, "r") | ||
precice_data_left = json.load(read_file) | ||
|
||
folder = os.path.dirname(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), fmi_file_right)) | ||
path = os.path.join(folder, os.path.basename(fmi_file_right)) | ||
read_file = open(path, "r") | ||
fmi_data_right = json.load(read_file) | ||
|
||
folder = os.path.dirname(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), precice_file_right)) | ||
path = os.path.join(folder, os.path.basename(precice_file_right)) | ||
read_file = open(path, "r") | ||
precice_data_right = json.load(read_file) | ||
|
||
|
||
# Define variables | ||
k_1 = fmi_data_left["model_params"]["spring_fixed.c"] | ||
k_2 = fmi_data_right["model_params"]["spring_fixed.c"] | ||
u0_1 = fmi_data_left["initial_conditions"]["mass.u"] | ||
u0_2 = fmi_data_right["initial_conditions"]["mass.u"] | ||
k_12_left = fmi_data_left["model_params"]["spring_middle.c"] | ||
k_12_right = fmi_data_right["model_params"]["spring_middle.c"] | ||
|
||
if k_12_left == k_12_right: | ||
k_12 = k_12_left | ||
else: | ||
raise Exception("k_12 has to be equal in both participants. Please adjust input values.") | ||
|
||
|
||
# Define analytical solution and read computed results | ||
K = np.array([[k_1 + k_12, -k_12], [-k_12, k_2 + k_12]]) | ||
eigenvalues, eigenvectors = np.linalg.eig(K) | ||
omega = np.sqrt(eigenvalues) | ||
A, B = eigenvectors | ||
c = np.linalg.solve(eigenvectors, [u0_1, u0_2]) | ||
|
||
if participant_name == Participant.MASS_LEFT.value: | ||
filename = fmi_data_left["simulation_params"]["output_file_name"] | ||
df = pd.read_csv(filename, delimiter=',') | ||
|
||
def u_analytical(t): return c[0] * A[0] * np.cos(omega[0] * t) + c[1] * A[1] * np.cos(omega[1] * t) | ||
|
||
elif participant_name == Participant.MASS_RIGHT.value: | ||
filename = fmi_data_right["simulation_params"]["output_file_name"] | ||
df = pd.read_csv(filename, delimiter=',') | ||
|
||
def u_analytical(t): return c[0] * B[0] * np.cos(omega[0] * t) + c[1] * B[1] * np.cos(omega[1] * t) | ||
|
||
times = df.iloc[:, 0] | ||
positions = df.iloc[:, 1] | ||
|
||
|
||
# Calculate error | ||
error = np.max(abs(u_analytical(np.array(times)) - np.array(positions))) | ||
print("Error w.r.t analytical solution:") | ||
print(f"{error}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
set -e -u | ||
|
||
. ../../tools/cleaning-tools.sh | ||
|
||
rm -rfv ./output/ | ||
|
||
clean_precice_logs . |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.