Skip to content
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

PolynomialPathFitter and other utilities for FunctionBasedPath #3581

Merged
merged 56 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4514fba
Draft utilities for adding FunctionBasedPaths
nickbianco Sep 18, 2023
fd5ec86
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 18, 2023
e700333
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 20, 2023
4b48e74
Fleshing out path utilities
nickbianco Sep 20, 2023
21b44d1
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 21, 2023
2ad259f
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 21, 2023
8a714ab
Simplify the new ModelOperator // start fleshing out path length comp…
nickbianco Sep 21, 2023
60ffecc
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 21, 2023
307a321
finalize path length and moment arm computation utility
nickbianco Sep 22, 2023
78335de
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 22, 2023
f23a75c
First pass at polynomial fitting utility
nickbianco Sep 25, 2023
9b44256
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 25, 2023
5c7d505
Testing the fitting utility
nickbianco Sep 25, 2023
2991448
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 25, 2023
d4376b3
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 25, 2023
57ebe85
Fitting utility is working!
nickbianco Sep 26, 2023
9450572
Fix merge conflict
nickbianco Sep 26, 2023
c4f329e
Merge branch 'function_based_path' into function_based_path_utils
nickbianco Sep 26, 2023
a336259
Prototyping a class for generating Latin hypercube designs
nickbianco Oct 2, 2023
d90672e
Re-arranging the new utilities
nickbianco Oct 2, 2023
9916560
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 2, 2023
84f16ae
Saving current progress on LHS designs
nickbianco Oct 2, 2023
ac3aaca
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 2, 2023
8a5ed38
Remove outdated Latin hypercube code
nickbianco Oct 9, 2023
7fe2852
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 9, 2023
d16a2ba
Start fleshing out a FunctionBasedPathFitter class
nickbianco Oct 9, 2023
579f18f
Move fitter to Actuators and rename to 'PolynomialPathFitter'
nickbianco Oct 10, 2023
3660f8c
Removing unnecessary whitespace changes
nickbianco Oct 10, 2023
149b18e
Undo more whitespace changes
nickbianco Oct 10, 2023
f01cbd7
Last set of whitespace undos
nickbianco Oct 10, 2023
fc4adca
A few more minor changes
nickbianco Oct 10, 2023
8715ab9
Coordinate-based sampling works!
nickbianco Oct 11, 2023
447def1
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 11, 2023
43d0ddc
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 13, 2023
1add512
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 13, 2023
088237d
Make path fitter outputs prettier
nickbianco Oct 16, 2023
5026d6c
Merge branch 'latin_hypercube_design' into function_based_path_utils
nickbianco Oct 16, 2023
f2726c0
Add bindings // lots of small updates
nickbianco Oct 17, 2023
f57f844
Fix the bindings for PolynomialPathFitter // small tweaks and fixes
nickbianco Oct 18, 2023
ded4fea
Add doc comments and property descriptions
nickbianco Oct 18, 2023
ebac89b
Clean up the output logging
nickbianco Oct 20, 2023
779fc62
Added main doc comments // other small additions
nickbianco Oct 20, 2023
3f83539
Remove debugging code
nickbianco Oct 20, 2023
82cab02
Update changelog
nickbianco Oct 20, 2023
4c52fc8
Merge branch 'main' into function_based_path_utils
nickbianco Oct 20, 2023
aaead77
Add testPolynomialPathFitter
nickbianco Oct 20, 2023
74ab617
Parens for boolean logic to fix Linux CI
nickbianco Oct 20, 2023
2e4b7e5
Set parallelization in test for CI
nickbianco Oct 20, 2023
fd01001
Addressing first round of review comments
nickbianco Oct 25, 2023
2d1a6fe
Fix testPolynomialPathFitter
nickbianco Oct 26, 2023
27a3c4d
Addressing review comments round 2
nickbianco Oct 26, 2023
5ed1300
Merge branch 'main' into function_based_path_utils
nickbianco Oct 27, 2023
21454e1
Updates to MultivariatePolynomialFunction
nickbianco Nov 2, 2023
d9fd62f
Make 'replacePathsWithFunctionBasedPaths' less confusing
nickbianco Nov 2, 2023
4b9c643
Merge branch 'main' into function_based_path_utils
nickbianco Nov 3, 2023
1f55352
Merge branch 'main' into function_based_path_utils
nickbianco Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ delete_this_to_stop_optimization*.txt
.idea/deployment.xml
.idea/other.xml

# Clang-Tidy
.clang-tidy

# CMake
cmake-build-*

Expand Down
3 changes: 2 additions & 1 deletion Bindings/OpenSimHeaders_actuators.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include <OpenSim/Actuators/DeGrooteFregly2016Muscle.h>

#include <OpenSim/Actuators/ModelFactory.h>

#include <OpenSim/Actuators/ModelProcessor.h>
#include <OpenSim/Actuators/ModelOperators.h>
#include <OpenSim/Actuators/PolynomialPathFitter.h>

#endif // OPENSIM_OPENSIM_HEADERS_ACTUATORS_H_
1 change: 1 addition & 0 deletions Bindings/actuators.i
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ namespace OpenSim {

%include <OpenSim/Actuators/ModelProcessor.h>
%include <OpenSim/Actuators/ModelOperators.h>
%include <OpenSim/Actuators/PolynomialPathFitter.h>
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ been added to these forces to provide access to concrete path types (e.g., `updP
- Fixed bindings to expose the method Model::getCoordinatesInMultibodyTreeOrder to scripting users (#3569)
- Fixed a bug where constructing a `ModelProcessor` from a `Model` object led to an invalid `Model`
- Added `LatinHypercubeDesign`, a class for generating Latin hypercube designs using random and algorithm methods (#3570)
- Added `PolynomialPathFitter`, A utility class for fitting a set of `FunctionBasedPath`s to existing geometry-path in
an OpenSim model using `MultivariatePolynomialFunction`s (#3390)

v4.4.1
======
Expand Down
23 changes: 23 additions & 0 deletions OpenSim/Actuators/ModelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,26 @@ void ModelFactory::createReserveActuators(Model& model, double optimalForce,
}
}

void ModelFactory::replacePathsWithFunctionBasedPaths(Model& model,
const Set<FunctionBasedPath>& functionBasedPaths) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The different meanings of "path" becomes confusing in this function...

for (int i = 0; i < functionBasedPaths.getSize(); ++i) {
auto path = functionBasedPaths.get(i);

// Get the force component associated with this path.
OPENSIM_THROW_IF(!model.hasComponent<Force>(path.getName()),
Exception, "Model does not contain a Force at path {}.",
path.getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Throw is already performed at updComponent calls, with similar message. Perhaps add info if needed, or remove the throw here?

auto& force = model.updComponent<Force>(path.getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that the name of the FunctionBasedPath is equal to the path of a component in a model. Is there a reason for this?


// Check that the force has a path property.
OPENSIM_THROW_IF(
!force.hasProperty("path"), Exception,
"Force {} does not have a path property.", path.getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throw does add new info, but does not use the throw from updProperty. Perhaps use try?


// Update the path.
path.setName(fmt::format("{}_path", force.getName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "path" to a PathActuator as the name of a FunctionBasedPath's name, postfixed with _path seems confusing.
If there are more functions out there that work like this it might become more confusing.
Is this postfix with _path a fix or feature? Why not use the name the user gave to this FunctionBasedPath?

force.updPropertyByName<AbstractPath>("path").setValue(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use try here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this name never change? Since "path" seems to be pretty ambiguous, someone might change the name of the property "path".

}
model.finalizeFromProperties();
model.finalizeConnections();
}
10 changes: 9 additions & 1 deletion OpenSim/Actuators/ModelFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* -------------------------------------------------------------------------- */

#include "osimActuatorsDLL.h"
#include <OpenSim/Simulation/Model/FunctionBasedPath.h>
#include <OpenSim/Simulation/Model/Model.h>
#include <OpenSim/Actuators/ModelProcessor.h>

namespace OpenSim {

Expand Down Expand Up @@ -89,7 +91,13 @@ class OSIMACTUATORS_API ModelFactory {
static void createReserveActuators(Model& model, double optimalForce,
double bound = SimTK::NaN,
bool skipCoordinatesWithExistingActuators = true);


/// Replace the paths of the forces in the model with the provided Set of
/// FunctionBasedPath%s. The name of each FunctionBasedPath should match the
/// path of a corresponding Force in the model. The path name is appended
/// with "_path" to avoid name ambiguity in the final model.
static void replacePathsWithFunctionBasedPaths(Model& model,
const Set<FunctionBasedPath>& functionBasedPaths);
};

} // namespace OpenSim
Expand Down
26 changes: 26 additions & 0 deletions OpenSim/Actuators/ModelOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,32 @@ class OSIMACTUATORS_API ModOpReplaceMusclesWithPathActuators
}
};

/// Invoke ModelFactory::replacePathsWithFunctionBasedPaths() on the model.
class OSIMACTUATORS_API ModOpReplacePathsWithFunctionBasedPaths
: public ModelOperator {
OpenSim_DECLARE_CONCRETE_OBJECT(
ModOpReplacePathsWithFunctionBasedPaths, ModelOperator);
OpenSim_DECLARE_PROPERTY(paths_file, std::string,
"Path to a file containing FunctionBasedPath definitions.");

public:
ModOpReplacePathsWithFunctionBasedPaths() {
constructProperty_paths_file("");
}
ModOpReplacePathsWithFunctionBasedPaths(std::string pathsFile) :
ModOpReplacePathsWithFunctionBasedPaths() {
set_paths_file(std::move(pathsFile));
}
void operate(Model& model, const std::string&) const override {
// Without finalizeFromProperties(), an exception is raised
// about the model not having any subcomponents.
model.finalizeFromProperties();
model.finalizeConnections();
ModelFactory::replacePathsWithFunctionBasedPaths(model,
Set<FunctionBasedPath>(get_paths_file()));
}
};

} // namespace OpenSim

#endif // OPENSIM_MODELOPERATORS_H
Loading