Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 1 deletion doc/world_builder_declarations.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@
"name": "${1:My Oceanic Plate}",
"coordinates": [],
"temperature models": [],
"composition models": []
"composition models": [],
"indicator models": []
}
},
{
Expand Down
12 changes: 12 additions & 0 deletions include/world_builder/features/oceanic_plate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ namespace WorldBuilder
{
class Interface;
} // namespace Density
namespace Indicator
{
class Interface;
} // namespace Indicator
} // namespace OceanicPlateModels

/**
Expand Down Expand Up @@ -183,6 +187,14 @@ namespace WorldBuilder
*/
std::vector<std::unique_ptr<Features::OceanicPlateModels::Density::Interface> > density_models;

/**
* A vector containing all the pointers to the indicator models. This vector is
* responsible for the features and has ownership over them. Therefore
* unique pointers are used.
* @see Features
*/
std::vector<std::unique_ptr<Features::OceanicPlateModels::Indicator::Interface> > indicator_models;

double min_depth;
Objects::Surface min_depth_surface;
double max_depth;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copyright (C) 2018-2026 by the authors of the World Builder code.

This file is part of the World Builder.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef WORLD_BUILDER_FEATURES_OCEANIC_PLATE_MODELS_INDICATOR_DEPTH_RANGE_H
#define WORLD_BUILDER_FEATURES_OCEANIC_PLATE_MODELS_INDICATOR_DEPTH_RANGE_H


#include "world_builder/features/oceanic_plate_models/indicator/interface.h"
#include "world_builder/features/feature_utilities.h"
#include "world_builder/objects/surface.h"

namespace WorldBuilder
{
namespace Features
{
using namespace FeatureUtilities;
namespace OceanicPlateModels
{
namespace Indicator
{
/**
* This class represents a oceanic plate and can implement submodules
Comment thread
lhy11009 marked this conversation as resolved.
* for indicator. These submodules determine what
* the returned indicator of the indicator functions of this class will be.
*/
class DepthRange final: public Interface
{
public:
/**
* constructor
*/
DepthRange(WorldBuilder::World *world);

/**
* Destructor
*/
~DepthRange() override final;

/**
* declare and read in the world builder file into the parameters class
*/
static
void declare_entries(Parameters &prm, const std::string &parent_name = "");

/**
* declare and read in the world builder file into the parameters class
*/
void parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates) override final;


/**
* Returns a indicator based on the given position, depth in the model,
* and current indicator
*/
double get_indicator(const Point<3> &position,
const Objects::NaturalCoordinate &position_in_natural_coordinates,
const double depth,
const unsigned int indicator_number,
double indicator,
const double feature_min_depth,
const double feature_max_depth) const override final;


private:
// depth-range indicator submodule parameters
double min_depth;
Objects::Surface min_depth_surface;
double max_depth;
Objects::Surface max_depth_surface;
std::vector<unsigned int> indicators;
Operations operation;
};
} // namespace Indicator
} // namespace OceanicPlateModels
} // namespace Features
} // namespace WorldBuilder

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
Copyright (C) 2018-2026 by the authors of the World Builder code.

This file is part of the World Builder.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef WORLD_BUILDER_FEATURES_OCEANIC_PLATE_MODELS_INDICATOR_INTERFACE_H
#define WORLD_BUILDER_FEATURES_OCEANIC_PLATE_MODELS_INDICATOR_INTERFACE_H


#include "world_builder/parameters.h"
#include "world_builder/objects/natural_coordinate.h"


namespace WorldBuilder
{
class World;
class Parameters;
template <unsigned int dim> class Point;

/**
* This class is an interface for the specific plate tectonic feature classes,
* such as oceanic plate, oceanic plate and subduction zone.
*/
namespace Features
{

namespace OceanicPlateModels
{
namespace Indicator
{
class ObjectFactory;

class Interface
{
public:
/**
* constructor
*/
Interface();

/**
* Destructor
*/
virtual
~Interface();

/**
* declare and read in the world builder file into the parameters class
*/
static
void declare_entries(Parameters &prm,
const std::string &parent_name,
const std::vector<std::string> &required_entries);

/**
* declare and read in the world builder file into the parameters class
*/
virtual
void parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates) = 0;


/**
* takes indicator and position and returns a indicator.
*/
virtual
double get_indicator(const Point<3> &position,
const Objects::NaturalCoordinate &position_in_natural_coordinates,
const double depth,
const unsigned int indicator_number,
double indicator,
const double feature_min_depth,
const double feature_max_depth) const = 0;
/**
* A function to register a new type. This is part of the automatic
* registration of the object factory.
*/
static void registerType(const std::string &name,
void ( * /*declare_entries*/)(Parameters &, const std::string &),
ObjectFactory *factory);


/**
* A function to create a new type. This is part of the automatic
* registration of the object factory.
*/
static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);

/**
* Returns the name of the plugin
*/
std::string get_name() const
{
return name;
};

protected:
/**
* A pointer to the world class to retrieve variables.
*/
WorldBuilder::World *world;

/**
* The name of the feature type.
*/
std::string name;

private:
static std::map<std::string, ObjectFactory *> &get_factory_map()
{
static std::map<std::string, ObjectFactory *> factories;
return factories;
}

static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
{
static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
return declares;
}

};


/**
* A class to create new objects
*/
class ObjectFactory
{
public:
virtual std::unique_ptr<Interface> create(World *world) = 0;
};

/**
* A macro which should be in every derived cpp file to automatically
* register it. Because this is a library, we need some extra measures
* to ensure that the static variable is actually initialized.
*/
#define WB_REGISTER_FEATURE_OCEANIC_PLATE_INDICATOR_MODEL(classname,name) \
class classname##Factory : public ObjectFactory { \
public: \
classname##Factory() \
{ \
Interface::registerType(#name, classname::declare_entries, this); \
} \
std::unique_ptr<Interface> create(World *world) override final { \
return std::unique_ptr<Interface>(new classname(world)); \
} \
}; \
static classname##Factory global_##classname##Factory;

} // namespace Indicator
} // namespace OceanicPlateModels
} // namespace Features
} // namespace WorldBuilder

#endif
24 changes: 24 additions & 0 deletions include/world_builder/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ namespace WorldBuilder
std::vector<composition_properties>
get_composition_properties(const std::string &name) const;

struct indicator_property
{
unsigned int index;
std::string name;
};

/**
* Parse indicator properties.
* The index is required, while name is optional.
* If the entry is absent, the vector is empty.
* \param name The name of the entry to be declared
*/
std::vector<indicator_property>
get_indicator_property(const std::string &name) const;

/**
* A specialized version of get which can return vectors/arrays
* of the indicator properties
* \param name The name of the entry to retrieved
*/
template<class T>
std::vector<T> get_vector(const std::string &name,
const std::map<unsigned int, indicator_property> &indicator_properties);

/**
* Declares the existence an entry in the parameters class.
* Default values are supplied by the type.
Expand Down
Loading
Loading