Philote-Cpp
C++ bindings for the Philote MDO standard
Loading...
Searching...
No Matches
philote::ExplicitDiscipline Class Reference

Explicit discipline class. More...

#include <explicit.h>

Inheritance diagram for philote::ExplicitDiscipline:
philote::Discipline Paraboloid Rosenbrock

Public Member Functions

 ExplicitDiscipline ()
 Construct a new Explicit Discipline object.
 
 ~ExplicitDiscipline () noexcept
 Destroy the Explicit Discipline object.
 
void RegisterServices (grpc::ServerBuilder &builder)
 Registers all services with a gRPC channel.
 
virtual void Compute (const philote::Variables &inputs, philote::Variables &outputs)
 Function evaluation for the discipline.
 
virtual void ComputePartials (const philote::Variables &inputs, Partials &partials)
 Gradient evaluation for the discipline.
 
- Public Member Functions inherited from philote::Discipline
 Discipline ()
 Construct a new Discipline object.
 
 ~Discipline () noexcept
 Destroy the Discipline object.
 
std::map< std::string, std::string > & options_list ()
 Gets the options list.
 
std::vector< philote::VariableMetaData > & var_meta ()
 Accesses the variable meta data.
 
const std::vector< philote::VariableMetaData > & var_meta () const noexcept
 
std::vector< philote::PartialsMetaData > & partials_meta ()
 Accesses the partials meta data.
 
const std::vector< philote::PartialsMetaData > & partials_meta () const noexcept
 
philote::DisciplineProperties & properties ()
 Gets the discipline properties.
 
philote::StreamOptions & stream_opts ()
 Gets the stream options.
 
const philote::StreamOptions & stream_opts () const noexcept
 
void AddInput (const std::string &name, const std::vector< int64_t > &shape, const std::string &units)
 Declares an input.
 
void AddOutput (const std::string &name, const std::vector< int64_t > &shape, const std::string &units)
 Declares an output.
 
void DeclarePartials (const std::string &f, const std::string &x)
 Declare a (set of) partial(s) for the discipline.
 
void AddOption (const std::string &name, const std::string &type)
 Add an option to the discipline.
 
virtual void Initialize ()
 Initialize function that sets up available options.
 
virtual void Configure ()
 Configure function that is called after options are set.
 
virtual void SetOptions (const google::protobuf::Struct &options_struct)
 Sets up all discipline options based on a protobuf struct that the server received from the client.
 
virtual void Setup ()
 Setup function that is called by the server when the client calls the setup RPC.
 
virtual void SetupPartials ()
 Setup function that is called by the server when the client calls the setup RPC.
 
void SetContext (grpc::ServerContext *context) const noexcept
 Set the gRPC server context for cancellation detection.
 
void ClearContext () const noexcept
 Clear the gRPC server context.
 
bool IsCancelled () const noexcept
 Check if the current operation has been cancelled.
 

Additional Inherited Members

- Protected Member Functions inherited from philote::Discipline
std::vector< int64_t > ComputePartialShape (const std::string &f, const std::string &x, bool allow_output_as_x)
 Computes the shape for a partial derivative df/dx.
 
- Protected Attributes inherited from philote::Discipline
std::map< std::string, std::string > options_list_
 List of options that can be set by the client.
 
std::vector< philote::VariableMetaData > var_meta_
 List of variable meta data.
 
std::vector< philote::PartialsMetaData > partials_meta_
 List of partials meta data.
 
philote::DisciplineProperties properties_
 Discipline properties.
 
philote::StreamOptions stream_opts_
 Stream options.
 
grpc::ServerContext * current_context_ = nullptr
 Current gRPC server context for cancellation detection (mutable for const correctness)
 

Detailed Description

Explicit discipline class.

This class should be overriden by discipline developers. The basic discipline and explicit discipline servers are private member variables of this class and are registered to a gRPC connection together via the RegisterServers member function. The discipline developer should not have to interact further with these services.

Explicit disciplines compute direct function evaluations (f(x) = y) and optionally their gradients. They are suitable for analyses where outputs can be computed directly from inputs without solving implicit equations.

Example: Simple Explicit Discipline
#include <explicit.h>
class SimpleFunction : public philote::ExplicitDiscipline {
private:
void Setup() override {
AddInput("x", {1}, "m");
AddOutput("y", {1}, "m");
}
void SetupPartials() override {
DeclarePartials("y", "x");
}
void Compute(const philote::Variables &inputs,
philote::Variables &outputs) override {
double x = inputs.at("x")(0);
outputs.at("y")(0) = 2.0 * x + 1.0;
}
void ComputePartials(const philote::Variables &inputs,
philote::Partials &partials) override {
partials[{"y", "x"}](0) = 2.0;
}
};
Explicit discipline class.
Definition explicit.h:263
std::map< std::string, philote::Variable > Variables
Definition variable.h:404
std::map< std::pair< std::string, std::string >, philote::Variable > Partials
Definition variable.h:405
Example: Multi-Input/Output Discipline
private:
void Setup() override {
AddInput("x", {1}, "m");
AddInput("y", {1}, "m");
AddOutput("f_xy", {1}, "m**2");
}
void SetupPartials() override {
DeclarePartials("f_xy", "x");
DeclarePartials("f_xy", "y");
}
void Compute(const philote::Variables &inputs,
philote::Variables &outputs) override {
double x = inputs.at("x")(0);
double y = inputs.at("y")(0);
outputs.at("f_xy")(0) = std::pow(x - 3.0, 2.0) + x * y +
std::pow(y + 4.0, 2.0) - 3.0;
}
void ComputePartials(const philote::Variables &inputs,
philote::Partials &partials) override {
double x = inputs.at("x")(0);
double y = inputs.at("y")(0);
partials[{"f_xy", "x"}](0) = 2.0 * x - 6.0 + y;
partials[{"f_xy", "y"}](0) = 2.0 * y + 8.0 + x;
}
};
Definition paraboloid_server.cpp:48
Example: Discipline with Options
class ConfigurableDiscipline : public philote::ExplicitDiscipline {
private:
double scale_factor_ = 1.0;
void Initialize() override {
ExplicitDiscipline::Initialize();
AddOption("scale_factor", "float");
}
void Configure() override {
// Options are set before Configure is called
// Access via discipline properties if needed
}
void Setup() override {
AddInput("x", {1}, "m");
AddOutput("y", {1}, "m");
}
void Compute(const philote::Variables &inputs,
philote::Variables &outputs) override {
outputs.at("y")(0) = scale_factor_ * inputs.at("x")(0);
}
};
Example: Starting a Server
#include <grpcpp/grpcpp.h>
int main() {
std::string address("localhost:50051");
Paraboloid discipline;
grpc::ServerBuilder builder;
builder.AddListeningPort(address, grpc::InsecureServerCredentials());
discipline.RegisterServices(builder);
std::unique_ptr<grpc::Server> server = builder.BuildAndStart();
std::cout << "Server listening on " << address << std::endl;
server->Wait();
return 0;
}
void RegisterServices(grpc::ServerBuilder &builder)
Registers all services with a gRPC channel.
int main()
Definition paraboloid_client.cpp:50
Note
Thread Safety: This class is NOT inherently thread-safe. Concurrent calls to Compute or ComputePartials from multiple RPC handlers will access the same instance without synchronization. User-defined implementations should add appropriate locks if they modify shared state or if thread safety is required.
See also
philote::ExplicitClient
philote::ImplicitDiscipline

Constructor & Destructor Documentation

◆ ExplicitDiscipline()

philote::ExplicitDiscipline::ExplicitDiscipline ( )

Construct a new Explicit Discipline object.

◆ ~ExplicitDiscipline()

philote::ExplicitDiscipline::~ExplicitDiscipline ( )
noexcept

Destroy the Explicit Discipline object.

Member Function Documentation

◆ Compute()

virtual void philote::ExplicitDiscipline::Compute ( const philote::Variables inputs,
philote::Variables outputs 
)
virtual

Function evaluation for the discipline.

This function should be overridden by the developer of the discipline.

Parameters
inputsinput variables for the discipline (continuous and discrete)
Returns
philote::Variables

◆ ComputePartials()

virtual void philote::ExplicitDiscipline::ComputePartials ( const philote::Variables inputs,
Partials partials 
)
virtual

Gradient evaluation for the discipline.

This function should be overridden by the developer of the discipline, if applicable (not every discipline can provide partials).

Parameters
inputsinput variables for the discipline (continuous and discrete)

◆ RegisterServices()

void philote::ExplicitDiscipline::RegisterServices ( grpc::ServerBuilder &  builder)

Registers all services with a gRPC channel.

Parameters
builder

The documentation for this class was generated from the following file: