Skip to content
Open
12 changes: 12 additions & 0 deletions include/world_builder/features/continental_plate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace WorldBuilder
{
class Interface;
} // namespace Temperature
namespace Density
{
class Interface;
} // namespace Density
} // namespace ContinentalPlateModels

/**
Expand Down Expand Up @@ -159,6 +163,14 @@ namespace WorldBuilder
*/
std::vector<std::unique_ptr<Features::ContinentalPlateModels::Velocity::Interface> > velocity_models;

/**
* A vector containing all the pointers to the composition 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::ContinentalPlateModels::Density::Interface> > density_models;


double min_depth;
Objects::Surface min_depth_surface;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
Copyright (C) 2018-2024 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_CONTINENTAL_PLATE_MODELS_DENSITY_INTERFACE_H
#define WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_MODELS_DENSITY_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 continental plate, oceanic plate and subduction zone.
*/
namespace Features
{

namespace ContinentalPlateModels
{
namespace Density
{
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 temperature and position and returns a temperature.
*/
virtual
double get_density(const Point<3> &position,
const Objects::NaturalCoordinate &position_in_natural_coordinates,
const double depth,
const double gravity,
double density,
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_CONTINENTAL_PLATE_DENSITY_MODEL(klass,name) \
class klass##Factory : public ObjectFactory { \
public: \
klass##Factory() \
{ \
Interface::registerType(#name, klass::declare_entries, this); \
} \
std::unique_ptr<Interface> create(World *world) override final { \
return std::unique_ptr<Interface>(new klass(world)); \
} \
}; \
static klass##Factory global_##klass##Factory;

} // namespace Density
} // namespace ContinentalPlateModels
} // namespace Features
} // namespace WorldBuilder

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
Copyright (C) 2018-2024 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_CONTINENTAL_PLATE_MODELS_DENSITY_UNIFORM_H
#define WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_MODELS_DENSITY_UNIFORM_H


#include "world_builder/features/continental_plate_models/density/interface.h"
#include "world_builder/features/feature_utilities.h"
#include "world_builder/objects/surface.h"


namespace WorldBuilder
{

namespace Features
{
using namespace FeatureUtilities;
namespace ContinentalPlateModels
{
namespace Density
{
/**
* This class represents a continental plate and can implement submodules
* for temperature and composition. These submodules determine what
* the returned temperature or composition of the temperature and composition
* functions of this class will be.
*/
class Uniform final: public Interface
{
public:
/**
* constructor
*/
Uniform(WorldBuilder::World *world);

/**
* Destructor
*/
~Uniform() 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 temperature based on the given position, depth in the model,
* gravity and current temperature.
*/
double get_density(const Point<3> &position,
const Objects::NaturalCoordinate &position_in_natural_coordinates,
const double depth,
const double gravity,
double density,
const double feature_min_depth,
const double feature_max_depth) const override final;


private:
// uniform temperature submodule parameters
double min_depth;
Objects::Surface min_depth_surface;
double max_depth;
Objects::Surface max_depth_surface;
std::vector<double> densities;
Operations operation;
std::vector<unsigned int> compositions;

};
} // namespace Density
} // namespace ContinentalPlateModels
} // namespace Features
} // namespace WorldBuilder

#endif
17 changes: 13 additions & 4 deletions include/world_builder/features/fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "world_builder/features/fault_models/grains/interface.h"
#include "world_builder/features/fault_models/temperature/interface.h"
#include "world_builder/features/fault_models/velocity/interface.h"
#include "world_builder/features/fault_models/density/interface.h"
#include "world_builder/objects/segment.h"
#include "world_builder/bounding_box.h"
#include "world_builder/objects/distance_from_surface.h"
Expand Down Expand Up @@ -55,6 +56,10 @@ namespace WorldBuilder
{
class Interface;
} // namespace Temperature
namespace Density
{
class Interface;
} // namespace Temperature
} // namespace FaultModels

/**
Expand Down Expand Up @@ -155,24 +160,28 @@ namespace WorldBuilder
std::vector<std::shared_ptr<Features::FaultModels::Composition::Interface> > default_composition_models;
std::vector<std::shared_ptr<Features::FaultModels::Grains::Interface> > default_grains_models;
std::vector<std::shared_ptr<Features::FaultModels::Velocity::Interface> > default_velocity_models;
std::vector<std::shared_ptr<Features::FaultModels::Density::Interface> > default_density_models;

std::vector<Objects::Segment<Features::FaultModels::Temperature::Interface,
Features::FaultModels::Composition::Interface,
Features::FaultModels::Grains::Interface,
Features::FaultModels::Velocity::Interface> > default_segment_vector;
Features::FaultModels::Velocity::Interface,
Features::FaultModels::Density::Interface> > default_segment_vector;

std::vector< std::vector<Objects::Segment<Features::FaultModels::Temperature::Interface,
Features::FaultModels::Composition::Interface,
Features::FaultModels::Grains::Interface,
Features::FaultModels::Velocity::Interface> > > sections_segment_vector;
Features::FaultModels::Velocity::Interface,
Features::FaultModels::Density::Interface> > > sections_segment_vector;

// This vector stores segments to this coordinate/section.
//First used (raw) pointers to the segment relevant to this coordinate/section,
// but I do not trust it won't fail when memory is moved. So storing the all the data now.
std::vector<std::vector<Objects::Segment<Features::FaultModels::Temperature::Interface,
Features::FaultModels::Composition::Interface,
Features::FaultModels::Grains::Interface,
Features::FaultModels::Velocity::Interface> > > segment_vector;
Features::FaultModels::Velocity::Interface,
Features::FaultModels::Density::Interface> > > segment_vector;

// todo: the memory of this can be greatly improved by
// or using a plugin system for the submodules, or
Expand Down Expand Up @@ -235,4 +244,4 @@ namespace WorldBuilder
} // namespace Features
} // namespace WorldBuilder

#endif
#endif
Loading