NEML2 1.4.0
Loading...
Searching...
No Matches
Factory Class Reference

Detailed Description

The factory is responsible for:

  1. retriving a NEML2Object given the object name as a std::string
  2. creating a NEML2Object given the type of the NEML2Object as a std::string.

#include <Factory.h>

Static Public Member Functions

static Factoryget ()
 Get the global Factory singleton.
 
template<class T >
static std::shared_ptr< T > get_object_ptr (const std::string &section, const std::string &name, const OptionSet &additional_options=OptionSet(), bool force_create=false)
 Retrive an object pointer under the given section with the given object name.
 
template<class T >
static T & get_object (const std::string &section, const std::string &name, const OptionSet &additional_options=OptionSet(), bool force_create=false)
 Retrive an object reference under the given section with the given object name.
 
static void load (const OptionCollection &all_options)
 Provide all objects' options to the factory. The factory is ready to manufacture objects after this call, e.g., through either manufacture, get_object, or get_object_ptr.
 
static void clear ()
 Destruct all the objects.
 
static void print (std::ostream &os=std::cout)
 List all the manufactured objects.
 

Static Public Attributes

static std::vector< std::string > pipeline = {"Tensors", "Solvers", "Data", "Models", "Drivers"}
 The sequence which we use to manufacture objects.
 

Protected Member Functions

void create_object (const std::string &section, const OptionSet &options)
 Manufacture a single NEML2Object.
 

Member Function Documentation

◆ clear()

void clear ( )
static

Destruct all the objects.

◆ create_object()

void create_object ( const std::string & section,
const OptionSet & options )
protected

Manufacture a single NEML2Object.

Parameters
sectionThe section which the object to be manufactured belongs to.
optionsThe options of the object.

◆ get()

Factory & get ( )
static

Get the global Factory singleton.

◆ get_object()

template<class T >
T & get_object ( const std::string & section,
const std::string & name,
const OptionSet & additional_options = OptionSet(),
bool force_create = false )
inlinestatic

Retrive an object reference under the given section with the given object name.

An exception is thrown if

  • the object with the given name does not exist, or
  • the object with the given name exists but does not have the correct type (e.g., dynamic case fails).
Template Parameters
TThe type of the NEML2Object
Parameters
sectionThe section name under which the search happens.
nameThe name of the object to retrieve.
additional_optionsAdditional input options to pass to the object constructor
force_create(Optional) Force the factory to create a new object even if the object has already been created.
Returns
T & The object reference.

◆ get_object_ptr()

template<class T >
std::shared_ptr< T > get_object_ptr ( const std::string & section,
const std::string & name,
const OptionSet & additional_options = OptionSet(),
bool force_create = false )
inlinestatic

Retrive an object pointer under the given section with the given object name.

An exception is thrown if

  • the object with the given name does not exist, or
  • the object with the given name exists but does not have the correct type (e.g., dynamic case fails).
Template Parameters
TThe type of the NEML2Object
Parameters
sectionThe section name under which the search happens.
nameThe name of the object to retrieve.
additional_optionsAdditional input options to pass to the object constructor
force_create(Optional) Force the factory to create a new object even if the object has already been created.
Returns
std::shared_ptr<T> The object pointer.

◆ load()

void load ( const OptionCollection & all_options)
static

Provide all objects' options to the factory. The factory is ready to manufacture objects after this call, e.g., through either manufacture, get_object, or get_object_ptr.

Parameters
all_optionsThe collection of all the options of the objects to be manufactured.

◆ print()

void print ( std::ostream & os = std::cout)
static

List all the manufactured objects.

Parameters
osThe stream to write to.

Member Data Documentation

◆ pipeline

std::vector< std::string > pipeline = {"Tensors", "Solvers", "Data", "Models", "Drivers"}
static

The sequence which we use to manufacture objects.