diff --git a/appl/conjugateheattransfer/iterative/main_freeflow.cc b/appl/conjugateheattransfer/iterative/main_freeflow.cc index adcc0537141ffdff1dd9f2430a77b5648b424372..8e1976d02ca50f7891671d02ca04626ff1c364bb 100644 --- a/appl/conjugateheattransfer/iterative/main_freeflow.cc +++ b/appl/conjugateheattransfer/iterative/main_freeflow.cc @@ -92,10 +92,12 @@ int main(int argc, char** argv) try // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - auto& couplingInterface = PreciceWrapper::getInstance(); + auto& couplingInterface = precice_wrapper::PreciceWrapper::getInstance(); couplingInterface.announceSolver( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); //couplingInterface.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); couplingInterface.configure( "precice-config.xml" ); + couplingInterface.announceHeatFluxToWrite( precice_wrapper::HeatFluxType::FreeFlow ); + couplingInterface.announceHeatFluxToRead( precice_wrapper::HeatFluxType::Solid ); const int dim = couplingInterface.getDimensions(); std::cout << dim << " " << int(FreeFlowFVGridGeometry::GridView::dimension) << std::endl; @@ -211,12 +213,8 @@ int main(int argc, char** argv) try couplingInterface.announceIterationCheckpointWritten(); } - // Read heat flux from precice - // TODO: Remove // when vertexSize is defined - // precice.readBlockScalarData( heatFluxId, vertexSize, vertexIDs.data(), heatFluxVec.data() ); - - // Make use of the heat flux here - // TODO + // Read heat flux from precice. + couplingInterface.readHeatFluxFromOtherSolver(); // set previous solution for storage evaluations assembler->setPreviousSolution(solOld); @@ -229,6 +227,11 @@ int main(int argc, char** argv) try solOld = sol; freeFlowGridVariables->advanceTimeStep(); + // Write heatflux to wrapper + //couplingInterface.writeHeatFluxOnFace( ... ) + //Tell wrapper that all values have been written + couplingInterface.writeHeatFluxToOtherSolver(); + if ( couplingInterface.hasToReadIterationCheckpoint() ) { //Read checkpoint @@ -247,13 +250,6 @@ int main(int argc, char** argv) try // report statistics of this time step timeLoop->reportTimeStep(); - // Get the temperature here - // TODO - - // Write temperature to preCICe - // TODO: Remove // when vertexSize is defined - //precice.writeBlockScalarData( temperatureId, vertexSize, vertexIDs.data(), temperatureVec.data() ); - // set new dt as suggested by newton solver const double preciceDt = couplingInterface.advance( timeLoop->timeStepSize() ); const double newDt = std::min( preciceDt, nonLinearSolver.suggestTimeStepSize( timeLoop->timeStepSize() ) ); diff --git a/appl/conjugateheattransfer/iterative/main_solidenergy.cc b/appl/conjugateheattransfer/iterative/main_solidenergy.cc index e381495c6e33a4c0f09042c69d09d9ce5e1fd942..5b52b406103d9e85655b1161560c24f57c56bbe7 100644 --- a/appl/conjugateheattransfer/iterative/main_solidenergy.cc +++ b/appl/conjugateheattransfer/iterative/main_solidenergy.cc @@ -88,10 +88,12 @@ int main(int argc, char** argv) try // Initialize preCICE.Tell preCICE about: // - Name of solver // - What rank of how many ranks this instance is - auto& couplingInterface = PreciceWrapper::getInstance(); + auto& couplingInterface = precice_wrapper::PreciceWrapper::getInstance(); couplingInterface.announceSolver( "SolidEnergy", mpiHelper.rank(), mpiHelper.size() ); // Configure preCICE. For now the config file is hardcoded. couplingInterface.configure( "precice-config.xml" ); + couplingInterface.announceHeatFluxToWrite( precice_wrapper::HeatFluxType::Solid ); + couplingInterface.announceHeatFluxToRead( precice_wrapper::HeatFluxType::FreeFlow ); const int dim = couplingInterface.getDimensions(); if (dim != int(SolidEnergyFVGridGeometry::GridView::dimension)) diff --git a/appl/conjugateheattransfer/iterative/precice-config.xml b/appl/conjugateheattransfer/iterative/precice-config.xml index 6faa8792da2a717cee45833a62023d157e39a1a1..916f5f356fadb789c9f9bded30ce33846ecb4875 100644 --- a/appl/conjugateheattransfer/iterative/precice-config.xml +++ b/appl/conjugateheattransfer/iterative/precice-config.xml @@ -8,31 +8,31 @@ <solver-interface dimensions="2"> - <data:scalar name="Temperature"/> - <data:scalar name="Heat-Flux"/> + <data:scalar name="FreeFlow-Heat-Flux"/> + <data:scalar name="Solid-Heat-Flux"/> <mesh name="FreeFlowMesh"> - <use-data name="Temperature" /> - <use-data name="Heat-Flux" /> + <use-data name="FreeFlow-Heat-Flux" /> + <use-data name="Solid-Heat-Flux" /> </mesh> <mesh name="SolidEnergyMesh"> - <use-data name="Temperature" /> - <use-data name="Heat-Flux" /> + <use-data name="FreeFlow-Heat-Flux" /> + <use-data name="Solid-Heat-Flux" /> </mesh> <participant name="FreeFlow"> <use-mesh name="FreeFlowMesh" provide="yes"/> - <write-data name="Temperature" mesh="FreeFlowMesh"/> - <write-data name="Heat-Flux" mesh="FreeFlowMesh"/> + <write-data name="FreeFlow-Heat-Flux" mesh="FreeFlowMesh"/> + <read-data name="Solid-Heat-Flux" mesh="FreeFlowMesh"/> </participant> <participant name="SolidEnergy"> <use-mesh name="FreeFlowMesh" from="FreeFlow"/> <use-mesh name="SolidEnergyMesh" provide="yes"/> - <read-data name="Temperature" mesh="SolidEnergyMesh"/> - <read-data name="Heat-Flux" mesh="SolidEnergyMesh"/> + <read-data name="FreeFlow-Heat-Flux" mesh="SolidEnergyMesh"/> + <write-data name="Solid-Heat-Flux" mesh="SolidEnergyMesh"/> <mapping:nearest-neighbor direction="read" from="FreeFlowMesh" to="SolidEnergyMesh" constraint="consistent"/> <!-- @@ -50,8 +50,8 @@ <max-time value="100"/> <timestep-length value="1" /> - <exchange data="Temperature" mesh="FreeFlowMesh" from="FreeFlow" to="SolidEnergy" /> - <exchange data="Heat-Flux" mesh="FreeFlowMesh" from="FreeFlow" to="SolidEnergy" initialize="false" /> + <exchange data="FreeFlow-Heat-Flux" mesh="FreeFlowMesh" from="FreeFlow" to="SolidEnergy" /> + <exchange data="Solid-Heat-Flux" mesh="FreeFlowMesh" from="FreeFlow" to="SolidEnergy" initialize="false" /> </coupling-scheme:parallel-explicit> </solver-interface> diff --git a/appl/conjugateheattransfer/iterative/precicewrapper.cc b/appl/conjugateheattransfer/iterative/precicewrapper.cc index 6f1f0d0d33f1c1bc6138f885aaf70dd50ab4960a..ae13e3817880fd5c59c29a9cc543e039d06bb8a1 100644 --- a/appl/conjugateheattransfer/iterative/precicewrapper.cc +++ b/appl/conjugateheattransfer/iterative/precicewrapper.cc @@ -2,9 +2,11 @@ #include <cassert> +using namespace precice_wrapper; + PreciceWrapper::PreciceWrapper(): wasCreated_(false), precice_(nullptr), meshWasCreated_(false), preciceWasInitialized_(false), - meshID_(0), temperatureID_(0), heatFluxID_(0), timeStepSize_(0.) + meshID_(0), freeFlowHeatFluxID_(0), solidHeatFluxID_(0), timeStepSize_(0.), writeHeatFluxType_(UNDEFINED), readHeatFluxType_(UNDEFINED) { } @@ -20,6 +22,16 @@ void PreciceWrapper::configure( const std::string& configurationFileName ) precice_->configure( configurationFileName ); } +void PreciceWrapper::announceHeatFluxToWrite(const HeatFluxType heatFluxType) +{ + writeHeatFluxType_ = heatFluxType; +} + +void PreciceWrapper::announceHeatFluxToRead(const HeatFluxType heatFluxType) +{ + readHeatFluxType_ = heatFluxType; +} + void PreciceWrapper::announceSolver( const std::string& name, const int rank, const int size ) { assert( precice_ == nullptr ); @@ -64,8 +76,11 @@ double PreciceWrapper::initialize() assert( wasCreated_ ); assert( meshWasCreated_ ); - temperatureID_ = precice_->getDataID( "Temperature", meshID_ ); - heatFluxID_ = precice_->getDataID( "Heat-Flux", meshID_ ); + solidHeatFluxID_ = precice_->getDataID( "Solid-Heat-Flux", meshID_ ); + freeFlowHeatFluxID_ = precice_->getDataID( "FreeFlow-Heat-Flux", meshID_ ); + + freeFlowHeatFlux_.resize( getNumberOfVertices() ); + solidHeatFlux_.resize( getNumberOfVertices() ); timeStepSize_ = precice_->initialize(); assert( timeStepSize_ > 0 ); @@ -107,20 +122,60 @@ size_t PreciceWrapper::getNumberOfVertices() return vertexIDs_.size(); } -double PreciceWrapper::getHeatFluxAtFace(const int faceID) const +double PreciceWrapper::getHeatFluxAtFace( const int faceID) const { assert( wasCreated_ ); const auto idx = indexMapper_.getPreciceId( faceID ); - assert(idx < heatFlux_.size() ); - return heatFlux_[idx]; + assert( readHeatFluxType_ != HeatFluxType::UNDEFINED ); + if (readHeatFluxType_ == HeatFluxType::FreeFlow) + { + assert(idx < freeFlowHeatFlux_.size() ); + return freeFlowHeatFlux_[idx]; + } + else + { + assert(idx < solidHeatFlux_.size() ); + return solidHeatFlux_[idx]; + } } -double PreciceWrapper::getTemperatureAtFace(const int faceID) const +void PreciceWrapper::writeHeatFluxOnFace(const int faceID, + const double value) { assert( wasCreated_ ); const auto idx = indexMapper_.getPreciceId( faceID ); - assert(idx < temperature_.size() ); - return temperature_[idx]; + assert( writeHeatFluxType_ != HeatFluxType::UNDEFINED ); + if ( writeHeatFluxType_ == HeatFluxType::FreeFlow ) + { + freeFlowHeatFlux_[idx] = value; + } + else + { + solidHeatFlux_[idx] = value; + } +} + +void PreciceWrapper::writeHeatFluxToOtherSolver() +{ + assert( wasCreated_ ); + assert( writeHeatFluxType_ != HeatFluxType::UNDEFINED ); + + if ( writeHeatFluxType_ == HeatFluxType::FreeFlow ) + writeBlockScalarDataToPrecice( freeFlowHeatFluxID_, freeFlowHeatFlux_ ); + else + writeBlockScalarDataToPrecice( solidHeatFluxID_, solidHeatFlux_ ); + +} + +void PreciceWrapper::readHeatFluxFromOtherSolver() +{ + assert( wasCreated_ ); + assert( readHeatFluxType_ != HeatFluxType::UNDEFINED ); + + if ( readHeatFluxType_ == HeatFluxType::FreeFlow ) + readBlockScalarDataFromPrecice( freeFlowHeatFluxID_, freeFlowHeatFlux_ ); + else + readBlockScalarDataFromPrecice( solidHeatFluxID_, solidHeatFlux_ ); } bool PreciceWrapper::isCoupledEntity(const int faceID) const @@ -197,6 +252,20 @@ void PreciceWrapper::actionIsFulfilled(const std::string& condition) precice_->fulfilledAction( condition ); } +void PreciceWrapper::readBlockScalarDataFromPrecice(const int dataID, std::vector<double> &data) +{ + assert( wasCreated_ ); + assert( vertexIDs.size() == data.size() ); + precice_->readBlockScalarData( dataID, vertexIDs_.size(), vertexIDs_.data(), data.data() ); +} + +void PreciceWrapper::writeBlockScalarDataToPrecice(const int dataID, std::vector<double> &data) +{ + assert( wasCreated_ ); + assert( vertexIDs.size() == data.size() ); + precice_->writeBlockScalarData( dataID, vertexIDs_.size(), vertexIDs_.data(), data.data() ); +} + bool PreciceWrapper::hasToWriteInitialData() { assert( wasCreated_ ); diff --git a/appl/conjugateheattransfer/iterative/precicewrapper.hh b/appl/conjugateheattransfer/iterative/precicewrapper.hh index 3dfff18f08c29038e95154d37e165b6f920ee3ff..f9f18c452a2fe5a505d8fad9d7b7f9906afc66c6 100644 --- a/appl/conjugateheattransfer/iterative/precicewrapper.hh +++ b/appl/conjugateheattransfer/iterative/precicewrapper.hh @@ -7,6 +7,12 @@ #include "dumuxpreciceindexwrapper.hh" +namespace precice_wrapper{ + + enum HeatFluxType + { + UNDEFINED, FreeFlow, Solid + }; class PreciceWrapper { @@ -19,20 +25,28 @@ private: bool checkIfActionIsRequired( const std::string& condition ); void actionIsFulfilled( const std::string& condition ); + + void readBlockScalarDataFromPrecice( const int dataID, std::vector<double>& data ); + void writeBlockScalarDataToPrecice( const int dataID, std::vector<double>& data ); + bool hasToWriteInitialData(); bool meshWasCreated_; bool preciceWasInitialized_; int meshID_; int dimension_; - int temperatureID_; - int heatFluxID_; + int freeFlowHeatFluxID_; + int solidHeatFluxID_; double timeStepSize_; + HeatFluxType writeHeatFluxType_; + HeatFluxType readHeatFluxType_; + + std::vector<int> vertexIDs_; //should be size_t - std::vector<double> temperature_; - std::vector<double> heatFlux_; + std::vector<double> freeFlowHeatFlux_; + std::vector<double> solidHeatFlux_; DumuxPreciceIndexMapper<int> indexMapper_; @@ -47,6 +61,9 @@ public: void announceSolver( const std::string& name, const int rank, const int size ); void configure( const std::string& configurationFileName ); + void announceHeatFluxToWrite( const HeatFluxType heatFluxType ); + void announceHeatFluxToRead( const HeatFluxType heatFluxType ); + int getDimensions(); // static int getMeshID( const std::string& meshName ); //static void setMeshName( const std::string& meshName ); @@ -79,10 +96,11 @@ public: double getHeatFluxAtFace( const int faceID ) const; - double getTemperatureAtFace( const int faceID ) const; + void writeHeatFluxOnFace( const int faceID, const double value ); + + void writeHeatFluxToOtherSolver(); + void readHeatFluxFromOtherSolver(); - void writeHeatFluxOnFace( const int faceID ); - void writeTemperatureOnFace( const int faceID ); bool isCoupledEntity( const int faceID ) const; @@ -114,5 +132,5 @@ public: }; - +} #endif diff --git a/appl/conjugateheattransfer/monolithic/problem_freeflow.hh b/appl/conjugateheattransfer/monolithic/problem_freeflow.hh index 9b3c5851e92cd4b6250d68bb424d71c734a69f76..f0f82bde31d4820f1f0505faac2e035bd87d933c 100644 --- a/appl/conjugateheattransfer/monolithic/problem_freeflow.hh +++ b/appl/conjugateheattransfer/monolithic/problem_freeflow.hh @@ -112,7 +112,7 @@ public: : ParentType(fvGridGeometry, "FreeFlow"), eps_(1e-6), couplingManager_(couplingManager) #else FreeFlowSubProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry) - : ParentType(fvGridGeometry, "FreeFlow"), eps_(1e-6), couplingInterface(PreciceWrapper::getInstance()) + : ParentType(fvGridGeometry, "FreeFlow"), eps_(1e-6), couplingInterface(precice_wrapper::PreciceWrapper::getInstance()) #endif { problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name"); @@ -287,7 +287,7 @@ private: #if ENABLEMONOLITHIC std::shared_ptr<CouplingManager> couplingManager_; #else - PreciceWrapper& couplingInterface; + precice_wrapper::PreciceWrapper& couplingInterface; #endif }; diff --git a/appl/conjugateheattransfer/monolithic/problem_heat.hh b/appl/conjugateheattransfer/monolithic/problem_heat.hh index 5acb802e570da535b8629a7e47ec649048dc8086..1f426e95dac7998b64e163a1a7de52526494f977 100644 --- a/appl/conjugateheattransfer/monolithic/problem_heat.hh +++ b/appl/conjugateheattransfer/monolithic/problem_heat.hh @@ -96,7 +96,7 @@ public: : ParentType(fvGridGeometry, "SolidEnergy"), eps_(1e-7), couplingManager_(couplingManager) #else HeatSubProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry) - : ParentType(fvGridGeometry, "SolidEnergy"), eps_(1e-7), couplingInterface( PreciceWrapper::getInstance() ) + : ParentType(fvGridGeometry, "SolidEnergy"), eps_(1e-7), couplingInterface( precice_wrapper::PreciceWrapper::getInstance() ) #endif { problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name"); @@ -228,7 +228,7 @@ private: #if ENABLEMONOLITHIC std::shared_ptr<CouplingManager> couplingManager_; #else - PreciceWrapper& couplingInterface; + precice_wrapper::PreciceWrapper& couplingInterface; #endif };