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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ enable_testing()
#
# Include function library
#
include(ModelFunctions)
include(FrameworkFunctions)
include(ConfigureFunctions)
include(MessageQuICC)

Expand Down
3 changes: 0 additions & 3 deletions Components/Common/cmake.d/setup/RegisterNonDimensional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ set(tags
MagneticReynolds
ModifiedElsasser
Mu
Nev
Nu
Omega
Omicron
Expand All @@ -48,8 +47,6 @@ set(tags
Roberts
Rossby
Sigma
StabilityMode
Sort
Tau
Taylor
Theta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ namespace Variable {
*/
void setPhysical(const std::map<std::string,MHDFloat>& parameters, const std::map<std::string,std::size_t>& boundary);

/**
* @brief Update the physical parameters of the simulation
*
* @param parameters Physical parameters
*/
void updatePhysical(const std::map<std::string,MHDFloat>& parameters);

/**
* @brief Set the mesh grid arrays
*
Expand Down
126 changes: 126 additions & 0 deletions Components/Framework/include/QuICC/Model/ConfigFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* @file ConfigFactory.hpp
* @brief Implementation of the physical model configuration factory
*/

#ifndef QUICC_CONFIGFACTORY_HPP
#define QUICC_CONFIGFACTORY_HPP

// System includes
//
#include <memory>
#include <vector>

// Project includes
//
#include "Environment/QuICCEnv.hpp"
#include "QuICC/Timers/StageTimer.hpp"
#include "Profiler/Interface.hpp"
#include "QuICC/Enums/GridPurpose.hpp"
#include "QuICC/Enums/FieldIds.hpp"
#include "QuICC/Io/Config/ConfigurationWriter.hpp"
#include "QuICC/Io/Config/Simulation/Physical.hpp"
#include "QuICC/Io/Config/Simulation/Boundary.hpp"

namespace QuICC {

/**
* @brief Implementation of the physical model factory
*/
template <class TModel> class ConfigFactory
{
public:
class ConfigApp
{
public:
ConfigApp(std::shared_ptr<Io::Config::ConfigurationWriter> spWriter)
: mspWriter(spWriter)
{};

/// Write configuration file
void run() {
this->mspWriter->init();
this->mspWriter->write();
};

/// Finalize
void finalize() {
this->mspWriter->finalize();
};

private:
std::shared_ptr<Io::Config::ConfigurationWriter> mspWriter;
};

/// Typedef of type of object created
typedef std::shared_ptr<ConfigApp> ReturnType;

/**
* @brief Create a shared simulation for the model
*/
static ReturnType create();

protected:

private:
/**
* @brief Constructor
*/
ConfigFactory();

/**
* @brief Destructor
*/
~ConfigFactory();
};

template <class TModel> typename ConfigFactory<TModel>::ReturnType ConfigFactory<TModel>::create()
{
// create model
TModel model;
model.init();

// Create and tune spatial scheme
auto spScheme = std::make_shared<typename TModel::SchemeType>(model.SchemeFormulation(), GridPurpose::SIMULATION);
model.tuneScheme(spScheme);

// Set dimension
int dim = spScheme->dimension();

// Set type string
std::string type = spScheme->tag();

// Box periodicity
std::vector<bool> isPeriodicBox = model.backend().isPeriodicBox();

// Create configuration writer
auto writer = std::make_shared<Io::Config::ConfigurationWriter>(dim, isPeriodicBox, type);

// Create list of field ID strings for boundary conditions
std::vector<std::string> bcNames = model.backend().fieldNames();

// Create list of nondimensional ID strings for physical parameters
std::vector<std::string> ndNames = model.backend().paramNames();

// Add the physical part
auto spPhys = std::make_shared<Io::Config::Simulation::Physical>(ndNames);
writer->rspSimulation()->addNode(Io::Config::Simulation::PHYSICAL, spPhys);

// Add the boundary part
auto spBound = std::make_shared<Io::Config::Simulation::Boundary>(bcNames);
writer->rspSimulation()->addNode(Io::Config::Simulation::BOUNDARY, spBound);

// Get model configuration tags
auto modelCfg = model.configTags();

// Add the model part
writer->rspModel()->addNodes(modelCfg);

auto spConfig = std::make_shared<ConfigFactory<TModel>::ConfigApp>(writer);

return spConfig;
}

}

#endif // QUICC_CONFIGFACTORY_HPP
136 changes: 136 additions & 0 deletions Components/Framework/include/QuICC/Model/IModelBuilder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* @file IModelBuilder.hpp
* @brief Interface for implementation of a physical model
*/

#ifndef QUICC_MODEL_IMODELBUILDER_HPP
#define QUICC_MODEL_IMODELBUILDER_HPP

// System includes
//
#include <vector>
#include <memory>

// Project includes
//
#include "QuICC/Model/IPhysicalModel.hpp"
#include "QuICC/Io/Variable/StateFileWriter.hpp"
#include "QuICC/Io/Variable/StateFileReader.hpp"

namespace QuICC {

namespace Model {

/**
* @brief Interface for the implementation of a physical models
*/
template <typename TSim> class IModelBuilder: public IPhysicalModel
{
public:
/**
* @brief Constructor
*/
IModelBuilder() = default;

/**
* @brief Destructor
*/
virtual ~IModelBuilder() = default;

/**
* @brief Add the required equations
*
* @param spSim Shared simulation object
*/
virtual void addEquations(std::shared_ptr<TSim> spSim) = 0;

/**
* @brief Add the required ASCII output files
*
* @param spSim Shared simulation object
*/
virtual void addAsciiOutputFiles(std::shared_ptr<TSim> spSim) = 0;

/**
* @brief Add the required HDF5 output files
*
* @param spSim Shared simulation object
*/
virtual void addHdf5OutputFiles(std::shared_ptr<TSim> spSim);

/**
* @brief Add the required statistics output files
*
* @param spSim Shared simulation object
*/
virtual void addStatsOutputFiles(std::shared_ptr<TSim> spSim);

/**
* @brief Set the initial state
*
* @param spSim Shared simulation object
*/
virtual void setInitialState(std::shared_ptr<TSim> spSim);

protected:

private:
};

template <typename TSim> void IModelBuilder<TSim>::addHdf5OutputFiles(std::shared_ptr<TSim> spSim)
{
// Field IDs iterator
std::vector<std::size_t> ids = this->backend().fieldIds();

// Create and add state file to IO
auto spState = std::make_shared<Io::Variable::StateFileWriter>(spSim->ss().tag(), spSim->ss().has(SpatialScheme::Feature::RegularSpectrum));
for(auto it = ids.cbegin(); it != ids.cend(); ++it)
{
spState->expect(*it);
}

// Add extra field names
ids.clear();
ids = this->extraFieldIds();
for(auto it = ids.cbegin(); it != ids.cend(); ++it)
{
spState->expect(*it);
}

spSim->addHdf5OutputFile(spState);
}

template <typename TSim> void IModelBuilder<TSim>::addStatsOutputFiles(std::shared_ptr<TSim>)
{
}

template <typename TSim> void IModelBuilder<TSim>::setInitialState(std::shared_ptr<TSim> spSim)
{
// Field IDs iterator
std::vector<std::size_t> ids = this->backend().fieldIds();

// Create and add initial state file to IO
auto spInit = std::make_shared<Io::Variable::StateFileReader>("_initial", spSim->ss().tag(), spSim->ss().has(SpatialScheme::Feature::RegularSpectrum));

// Set expected field names
for(auto it = ids.cbegin(); it != ids.cend(); ++it)
{
spInit->expect(*it);
}

// Add extra field names
ids.clear();
ids = this->extraFieldIds();
for(auto it = ids.cbegin(); it != ids.cend(); ++it)
{
spInit->expect(*it);
}

// Set simulation state
spSim->setInitialState(spInit);
}

}
}

#endif // QUICC_MODEL_IMODELBUILDER_HPP
Loading