Skip to content

Commit

Permalink
Port cpp elastictube1d solvers to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonis committed Jan 10, 2024
1 parent 5a5c695 commit 29d27d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion elastic-tube-1d/fluid-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STRE
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
endif()

find_package(precice REQUIRED CONFIG)
find_package(precice 3 REQUIRED CONFIG)
find_package(LAPACK REQUIRED)

add_executable(FluidSolver
Expand Down
22 changes: 11 additions & 11 deletions elastic-tube-1d/fluid-cpp/src/FluidSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include <vector>
#include <cmath>
#include "precice/SolverInterface.hpp"
#include "precice/precice.hpp"

using namespace precice;

Expand All @@ -29,13 +29,13 @@ int main(int argc, char **argv)

std::string outputFilePrefix = "./output/out_fluid"; //extra

SolverInterface interface(solverName, configFileName, 0, 1);
precice::Participant interface(solverName, configFileName, 0, 1);
std::cout << "preCICE configured..." << std::endl;

const int dimensions = interface.getDimensions();
auto meshName = "Fluid-Nodes-Mesh";
auto pressureName = "Pressure";
auto crossSectionLengthName = "CrossSectionLength";
const int dimensions = interface.getMeshDimensions(meshName);

std::vector<int> vertexIDs(chunkLength);

Expand Down Expand Up @@ -69,17 +69,17 @@ int main(int argc, char **argv)
}
}

interface.setMeshVertices(meshName, chunkLength, grid.data(), vertexIDs.data());
interface.setMeshVertices(meshName, grid, vertexIDs);

if (interface.requiresInitialData()) {
interface.writeBlockScalarData(meshName, pressureName, chunkLength, vertexIDs.data(), pressure.data());
interface.writeData(meshName, pressureName, vertexIDs, pressure);
}

double t = 0.0;
std::cout << "Initialize preCICE..." << std::endl;
double dt = interface.initialize();
interface.initialize();

interface.readBlockScalarData(meshName, crossSectionLengthName, chunkLength, vertexIDs.data(), crossSectionLength.data());
interface.readData(meshName, crossSectionLengthName, vertexIDs, 0, crossSectionLength);

std::copy(crossSectionLength.begin(), crossSectionLength.end(), crossSectionLength_old.begin());

Expand All @@ -93,6 +93,8 @@ int main(int argc, char **argv)
while (interface.isCouplingOngoing()) {
if (interface.requiresWritingCheckpoint()) {
}

auto dt = interface.getMaxTimeStepSize();

fluidComputeSolutionSerial(
// values from last time window
Expand All @@ -107,12 +109,11 @@ int main(int argc, char **argv)
velocity.data(),
pressure.data());

interface.writeBlockScalarData(meshName, pressureName, chunkLength, vertexIDs.data(), pressure.data());
interface.writeData(meshName, pressureName, vertexIDs, pressure);

interface.advance(dt);

//interface.readBlockScalarData(crossSectionLengthID, chunkLength, vertexIDs.data(), crossSectionLength.data());
interface.readBlockScalarData(meshName,crossSectionLengthName, chunkLength, vertexIDs.data(), crossSectionLength.data());
interface.readData(meshName,crossSectionLengthName, vertexIDs, interface.getMaxTimeStepSize(), crossSectionLength);

if (interface.requiresReadingCheckpoint()) {
} else {
Expand All @@ -128,6 +129,5 @@ int main(int argc, char **argv)
}

std::cout << "Exiting FluidSolver" << std::endl;
interface.finalize();
return 0;
}
2 changes: 1 addition & 1 deletion elastic-tube-1d/precice-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<coupling-scheme:serial-implicit>
<participants first="Fluid" second="Solid" />
<max-time value="1.0" />
<time-window-size value="0.01" valid-digits="8" />
<time-window-size value="0.01" />
<max-iterations value="40" />
<exchange data="Pressure" mesh="Fluid-Nodes-Mesh" from="Fluid" to="Solid" />
<exchange
Expand Down
2 changes: 1 addition & 1 deletion elastic-tube-1d/solid-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STRE
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
endif()

find_package(precice REQUIRED CONFIG)
find_package(precice 3 REQUIRED CONFIG)

add_executable(SolidSolver
src/SolidComputeSolution.cpp
Expand Down
18 changes: 9 additions & 9 deletions elastic-tube-1d/solid-cpp/src/SolidSolver.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SolidSolver.h"
#include <iostream>
#include <stdlib.h>
#include "precice/SolverInterface.hpp"
#include "precice/precice.hpp"

int main(int argc, char **argv)
{
Expand All @@ -24,13 +24,13 @@ int main(int argc, char **argv)

const std::string solverName = "Solid";

SolverInterface interface(solverName, configFileName, 0, 1);
precice::Participant interface(solverName, configFileName, 0, 1);
std::cout << "preCICE configured..." << std::endl;

int dimensions = interface.getDimensions();
auto meshName = "Solid-Nodes-Mesh";
auto crossSectionLengthName = "CrossSectionLength";
auto pressureName = "Pressure";
const int dimensions = interface.getMeshDimensions(meshName);

std::vector<double> pressure(chunkLength, 0.0);
std::vector<double> crossSectionLength(chunkLength, 1.0);
Expand All @@ -43,24 +43,25 @@ int main(int argc, char **argv)
}

std::vector<int> vertexIDs(chunkLength);
interface.setMeshVertices(meshName, chunkLength, grid.data(), vertexIDs.data());
interface.setMeshVertices(meshName, grid, vertexIDs);

if (interface.requiresInitialData()) {
interface.writeBlockScalarData(meshName, crossSectionLengthName, chunkLength, vertexIDs.data(), crossSectionLength.data());
interface.writeData(meshName, crossSectionLengthName, vertexIDs, crossSectionLength);
}

std::cout << "Initialize preCICE..." << std::endl;
double dt = interface.initialize();
interface.initialize();

while (interface.isCouplingOngoing()) {
if (interface.requiresWritingCheckpoint()) {
}
double dt = interface.getMaxTimeStepSize();

interface.readBlockScalarData(meshName, pressureName, chunkLength, vertexIDs.data(), pressure.data());
interface.readData(meshName, pressureName, vertexIDs, dt, pressure);

SolidComputeSolution(chunkLength, pressure.data(), crossSectionLength.data()); // Call Solver

interface.writeBlockScalarData(meshName, crossSectionLengthName, chunkLength, vertexIDs.data(), crossSectionLength.data());
interface.writeData(meshName, crossSectionLengthName, vertexIDs, crossSectionLength);

interface.advance(dt);

Expand All @@ -69,6 +70,5 @@ int main(int argc, char **argv)
}

std::cout << "Exiting SolidSolver" << std::endl;
interface.finalize();
return 0;
}

0 comments on commit 29d27d6

Please sign in to comment.