Commit d4b0426e authored by Alexander Jaust's avatar Alexander Jaust
Browse files

WIP: extending precice adapter

- Allow precice adapter to use / return vector quantities using Dune::FieldVector (testing)
- preCICE adapter uses a new internal reprsentation of the coupling data (interfaceData_)
parent ece82e03
......@@ -501,6 +501,10 @@ catch (Dune::Exception &e)
std::cerr << "Dune reported error: " << e << " ---> Abort!" << std::endl;
return 3;
}
catch (std::runtime_error &e) {
std::cerr << "Most likely preCICE reported an error: " << e.what() << " ---> Abort!" << std::endl;
return 5;
}
catch (...)
{
std::cerr << "Unknown exception thrown! ---> Abort!" << std::endl;
......
......@@ -357,7 +357,6 @@ int main(int argc, char** argv) try
const auto velocityId = couplingInterface.announceQuantity( "Velocity" );
const auto pressureId = couplingInterface.announceQuantity( "Pressure" );
const auto velocityVectorId = couplingInterface.announceVectorQuantity<2>( "VelocityVector" );
darcyProblem->updatePreciceDataIds();
......@@ -544,6 +543,10 @@ catch (Dune::Exception &e)
std::cerr << "Dune reported error: " << e << " ---> Abort!" << std::endl;
return 3;
}
catch (std::runtime_error &e) {
std::cerr << "Most likely preCICE reported an error: " << e.what() << " ---> Abort!" << std::endl;
return 5;
}
catch (...)
{
std::cerr << "Unknown exception thrown! ---> Abort!" << std::endl;
......
......@@ -15,6 +15,22 @@ namespace precice_adapter{
template<unsigned DIM>
using VectorXd = Dune::DenseVector<Dune::FieldVector<double, DIM>>;
struct DataContainer {
const std::string name;
const int preciceDataID;
std::vector<double> data;
const bool isVectorData;
DataContainer( const std::string& name,
const int dataID,
const size_t dataSize,
const bool isVectorData ) : name(name), preciceDataID( dataID ), isVectorData( isVectorData )
{
data.resize( dataSize );
}
};
class PreciceAdapter
{
......@@ -30,8 +46,6 @@ namespace precice_adapter{
void readBlockScalarDataFromPrecice( const int dataID, std::vector<double>& data );
void writeBlockScalarDataToPrecice( const int dataID, std::vector<double>& data );
size_t numberOfQuantities() const { return dataNames_.size(); }
bool meshWasCreated_;
bool preciceWasInitialized_;
bool hasIndexMapper_;
......@@ -39,15 +53,22 @@ namespace precice_adapter{
double timeStepSize_;
std::vector< std::string > dataNames_;
std::vector< int > preciceDataID_;
std::vector< std::vector< double > > dataVectors_;
// std::vector< int > preciceDataID_;
// std::vector< std::vector< double > > dataVectors_;
std::vector< DataContainer > interfaceData_;
std::vector<int> vertexIDs_; //should be size_t
DumuxPreciceIndexMapper<int> indexMapper_;
size_t getNumberOfQuantities() const { return dataNames_.size(); }
size_t getNumberOfQuantities() const { return interfaceData_.size(); }
auto getDataIterator( const std::string& name ) const {
auto dataName = [name](const DataContainer& item) { return item.name == name; };
auto it = std::find_if( interfaceData_.begin(), interfaceData_.end(), dataName );
return it;
}
static constexpr size_t reserveSize_ = 4;
......@@ -147,14 +168,19 @@ namespace precice_adapter{
template<unsigned DIM>
size_t PreciceAdapter::announceQuantity( const std::string& name ) {
assert( meshWasCreated_ );
auto it = std::find(dataNames_.begin(), dataNames_.end(), name);
if ( it != dataNames_.end() )
// Check if data is already announced
auto it = getDataIterator( name );
if ( it != interfaceData_.end() )
{
throw( std::runtime_error(" Error! Duplicate quantity announced! ") );
}
dataNames_.push_back( name );
preciceDataID_.push_back( precice_->getDataID( name, meshID_ ) );
dataVectors_.push_back( std::vector<double>( vertexIDs_.size() * DIM ) );
interfaceData_.push_back( DataContainer(name,
precice_->getDataID( name, meshID_ ),
vertexIDs_.size() * DIM,
DIM == getDimensions() )
);
return getNumberOfQuantities()-1;
}
......@@ -165,8 +191,9 @@ namespace precice_adapter{
//TODO
assert( DIM == getDimensions() );
const auto idx = indexMapper_.getPreciceId( faceID );
assert( dataID < dataVectors_.size() );
const std::vector<double>& quantityVector = dataVectors_[ dataID ];
assert( dataID < interfaceData_.size() );
assert( interfaceData_[dataID].isVectorData );
const std::vector<double>& quantityVector = interfaceData_[ dataID ].data;
assert(idx < quantityVector.size() );
VectorXd<DIM> vector;
......@@ -187,8 +214,9 @@ namespace precice_adapter{
}
const auto idx = indexMapper_.getPreciceId( faceID );
assert( dataID < dataVectors_.size() );
std::vector<double>& quantityVector = dataVectors_[ dataID ];
assert( dataID < interfaceData_.size() );
assert( interfaceData_[dataID].isVectorData );
std::vector<double>& quantityVector = interfaceData_[ dataID ].data;
assert( idx < quantityVector.size() );
assert( idx*DIM + DIM - 1 < quantityVector.size() );
......
......@@ -10,9 +10,7 @@ PreciceAdapter::PreciceAdapter():
wasCreated_(false), precice_(nullptr), meshWasCreated_(false), preciceWasInitialized_(false), hasIndexMapper_(false),
meshID_(0), timeStepSize_(0.)
{
preciceDataID_.reserve(reserveSize_);
dataNames_.reserve(reserveSize_);
dataVectors_.reserve(reserveSize_);
interfaceData_.reserve(reserveSize_);
}
PreciceAdapter& PreciceAdapter::getInstance()
......@@ -127,8 +125,8 @@ double PreciceAdapter::getScalarQuantityOnFace(const size_t dataID, const int fa
throw std::runtime_error("Reading quantity using faceID, but index mapping was not created!");
}
const auto idx = indexMapper_.getPreciceId( faceID );
assert( dataID < dataVectors_.size() );
const std::vector<double>& quantityVector = dataVectors_[ dataID ];
assert( dataID < interfaceData_.size() );
const std::vector<double>& quantityVector = interfaceData_[ dataID ].data;
assert(idx < quantityVector.size() );
return quantityVector[idx];
}
......@@ -142,8 +140,8 @@ void PreciceAdapter::writeScalarQuantityOnFace(const size_t dataID, const int fa
throw std::runtime_error("Writing quantity using faceID, but index mapping was not created!");
}
const auto idx = indexMapper_.getPreciceId( faceID );
assert( dataID < dataVectors_.size() );
std::vector<double>& quantityVector = dataVectors_[ dataID ];
assert( dataID < interfaceData_.size() );
std::vector<double>& quantityVector = interfaceData_[ dataID ].data;
assert( idx < quantityVector.size() );
quantityVector[idx] = value;
}
......@@ -161,8 +159,8 @@ void PreciceAdapter::writeScalarQuantityOnFace(const size_t dataID, const int fa
// throw std::runtime_error("Writing quantity using faceID, but index mapping was not created!");
// }
// const auto idx = indexMapper_.getPreciceId( faceID ) * size;
// assert( dataID < dataVectors_.size() );
// std::vector<double>& quantityVector = dataVectors_[ dataID ];
// assert( dataID < interfaceData_.size() );
// std::vector<double>& quantityVector = interfaceData_[ dataID ].data;
// assert( idx < quantityVector.size() );
// //quantityVector[idx] = value;
// std::copy_n( value, size, quantityVector[idx] );
......@@ -171,8 +169,8 @@ void PreciceAdapter::writeScalarQuantityOnFace(const size_t dataID, const int fa
std::vector<double>& PreciceAdapter::getQuantityVector(const size_t dataID )
{
assert( wasCreated_ );
assert( dataID < dataVectors_.size() );
return dataVectors_[dataID];
assert( dataID < interfaceData_.size() );
return interfaceData_[dataID].data;
}
const std::vector<double> &PreciceAdapter::getQuantityVector(const size_t dataID ) const
......@@ -185,27 +183,25 @@ void PreciceAdapter::writeScalarQuantityVector(const size_t dataID,
std::vector<double> &values)
{
assert( wasCreated_);
assert( dataID < dataVectors_.size() );
assert( dataVectors_[dataID].size() == values.size() );
dataVectors_[dataID] = values;
assert( dataID < interfaceData_.size() );
assert( interfaceData_[dataID].data.size() == values.size() );
interfaceData_[dataID].data = values;
}
void PreciceAdapter::writeScalarQuantityToOtherSolver(const size_t dataID)
{
assert( wasCreated_ );
assert( dataID < dataVectors_.size() );
assert( dataID < preciceDataID_.size() );
assert( dataID < interfaceData_.size() );
assert( dataID < std::numeric_limits<int>::max() );
writeBlockScalarDataToPrecice( preciceDataID_[dataID], dataVectors_[dataID] );
writeBlockScalarDataToPrecice( interfaceData_[dataID].preciceDataID, interfaceData_[dataID].data );
}
void PreciceAdapter::readScalarQuantityFromOtherSolver(const size_t dataID)
{
assert( wasCreated_ );
assert( dataID < dataVectors_.size() );
assert( dataID < preciceDataID_.size() );
assert( dataID < interfaceData_.size() );
assert( dataID < std::numeric_limits<int>::max() );
readBlockScalarDataFromPrecice( preciceDataID_[dataID], dataVectors_[dataID] );
readBlockScalarDataFromPrecice( interfaceData_[dataID].preciceDataID, interfaceData_[dataID].data );
}
bool PreciceAdapter::isCoupledEntity(const int faceID) const
......@@ -217,12 +213,13 @@ bool PreciceAdapter::isCoupledEntity(const int faceID) const
size_t PreciceAdapter::getIdFromName(const std::string &dataName) const
{
assert( wasCreated_ );
const auto it = std::find( dataNames_.begin(), dataNames_.end(), dataName );
if ( it == dataNames_.end() )
// Check if data is actually there
const auto it = getDataIterator( dataName );
if ( it == interfaceData_.end() )
{
throw( std::runtime_error(" Error! Name of data not found! ") );
}
const auto idx = std::distance( dataNames_.begin(), it );
const auto idx = std::distance( interfaceData_.begin(), it );
assert( idx > -1 );
return size_t(idx);
}
......@@ -230,8 +227,8 @@ size_t PreciceAdapter::getIdFromName(const std::string &dataName) const
std::string PreciceAdapter::getNameFromId(const size_t dataID) const
{
assert( wasCreated_ );
assert( dataID < dataNames_.size() );
return dataNames_[dataID];
assert( dataID < interfaceData_.size() );
return interfaceData_[dataID].name;
}
void PreciceAdapter::print(std::ostream& os)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment