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

Added InterfaceBuilder to improve ergonomics of creating our CFD interface #352

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ddement
Copy link
Collaborator

@ddement ddement commented Feb 10, 2025

No description provided.

@ddement ddement marked this pull request as ready for review February 10, 2025 21:22
@ddement ddement self-assigned this Feb 10, 2025
Copy link
Collaborator

@deslaughter deslaughter left a comment

Choose a reason for hiding this comment

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

I like the overall concept and it better documents the values that the user species.

My main concern is the ability of a user to discover which fields must be set. That will need to be documented or the builder will need to keep track of which values have been set and throw an error on the final build call after checking all the inputs. I found there was also something called a Step Builder which uses additional interfaces to expose different functions at various stages of the build. Might be worth looking into.

I think that I'd also prefer a AddMooringLine() function instead of SetNumberOfMooringLines(3) and then specifying an index number. Then the SetMooringLine*() functions could just set the values in the last index of the vector (after checking that there is at least one mooring line). This will visually separate the mooring lines functions into groups and prevents a whole class of indexing issues.

By the way, the functions to set the fair lead velocity and acceleration need to be removed and some code added in Build to calculate those values based on the platform node velocity and acceleration, since they're rigidly connected. I'll have the necessary functions in the model.hpp class soon, but you can go ahead and drop those methods from the builder.

Thanks for putting this together.

@faisal-bhuiyan faisal-bhuiyan added the code-refactoring Refactoring code to improve readability, maintainability, efficiency etc. label Feb 13, 2025
@@ -21,7 +21,7 @@ struct FloatingPlatformInput {
std::array<double, 6> acceleration{0., 0., 0., 0., 0., 0.};

/// Platform point mass matrix
std::array<std::array<double, 6>, 6> mass_matrix;
std::array<std::array<double, 6>, 6> mass_matrix{};

/// Mooring line array
std::vector<MooringLineInput> mooring_lines;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use brace initializer here as well?

std::vector<MooringLineInput> mooring_lines{};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried that. Clang-Tidy had some reason for not liking it there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a trailing whitespace in this file -- let's remove it.

target_sources(openturbine_library
  PRIVATE
  interface.cpp
)

install(FILES
  floating_platform.hpp
  floating_platform_input.hpp
  interface.hpp
  interface_builder.hpp
  interface_input.hpp
  mooring_line.hpp
  mooring_line_input.hpp
  node_data.hpp
  turbine.hpp
  turbine_input.hpp
  DESTINATION include/OpenTurbine/interfaces/cfd/
)

[[nodiscard]] Interface Build() const { return Interface(interface_in); }

private:
InterfaceInput interface_in;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's call this interface_input or just input?

Comment on lines 58 to 61
InterfaceBuilder& SetNumberOfMooringLines(size_t number_of_mooring_lines) {
interface_in.turbine.floating_platform.mooring_lines.resize(number_of_mooring_lines);
return *this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could shorten the argument names here, without losing any readability benefits. E.g.

    InterfaceBuilder& SetNumberOfMooringLines(size_t n) {
        interface_in.turbine.floating_platform.mooring_lines.resize(n);
        return *this;
    }


namespace openturbine::cfd {

struct InterfaceBuilder {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we call it BuildInterface to be consistent with how we named our other factory methods (such as CreateBeams)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was trying to be consistent with the Builder Pattern, where things are named this way by convention. I'm open to changing it if there are strong opinions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No strong opinion here, wanted to make sure we are being consistent within the codebase.

return *this;
}

[[nodiscard]] Interface Build() const { return Interface(interface_in); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to add some validation logic here to make sure we provide some guardrails for user error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. I am thinking these guardrails will come once we have fully fleshed out the interface and added other features (such as an actual turbine). I'd have to rely on yall to know what would make sense to check in this domain beyond certain obvious things (negative mass, etc).

@faisal-bhuiyan faisal-bhuiyan linked an issue Feb 17, 2025 that may be closed by this pull request
@ddement ddement requested a review from deslaughter February 28, 2025 21:32
@ddement
Copy link
Collaborator Author

ddement commented Feb 28, 2025

@deslaughter I've put together a prototype implementation of the a step-builder version of the interface. I'd love your feedback on it. See the FloatingPlatform regression test for a comparison of it versus the traditional builder. Obviously, the implementation needs a little clean up, but I wanted to get your input before I blew away the old stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-refactoring Refactoring code to improve readability, maintainability, efficiency etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write Builder class for Interface
3 participants