Skip to content

Commit e729744

Browse files
committed
Cleanup porting guide example
1 parent 4b167ce commit e729744

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

pages/docs/couple-your-code/couple-your-code-porting-v2-3.md

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,88 +23,84 @@ Please add breaking changes here when merged to the `develop` branch.
2323

2424
turnOnSolver(); //e.g. setup and partition mesh
2525

26-
- precice::SolverInterface interface("FluidSolver","precice-config.xml",rank,size); // constructor
27-
+ precice::Participant participant("FluidSolver","precice-config.xml",rank,size); // constructor
26+
- precice::SolverInterface participant("FluidSolver","precice-config.xml",rank,size); // constructor
27+
+ precice::Participant participant("FluidSolver","precice-config.xml",rank,size); // constructor
2828

2929
- const std::string& coric = precice::constants::actionReadIterationCheckpoint();
3030
- const std::string& cowic = precice::constants::actionWriteIterationCheckpoint();
3131
- const std::string& cowid = precice::constants::actionWriteInitialData();
3232

33-
- int dim = interface.getDimension();
33+
- int dim = participant.getDimension();
3434
+ int dim = participant.getMeshDimensions("FluidMesh");
3535
- int meshID = precice.getMeshID("FluidMesh");
36+
3637
int vertexSize; // number of vertices at wet surface
37-
38-
// determine vertexSize
39-
- double* coords = new double[vertexSize*dim]; // coords of vertices at wet surface
40-
+ std::vector<double> coords(vertexSize*dim); // coords of vertices at wet surface
41-
38+
// determine vertex count
39+
40+
std::vector<double> coords(vertexSize*dim); // coords of vertices at wet surface
4241
// determine coordinates
43-
- int* vertexIDs = new int[vertexSize];
44-
- precice.setMeshVertices(meshID, vertexSize, coords, vertexIDs);
45-
- delete[] coords;
46-
+ std::vector<int> vertexIDs(vertexSize);
42+
43+
std::vector<int> vertexIDs(vertexSize);
44+
- precice.setMeshVertices(meshID, vertexSize, coords.data(), vertexIDs.data());
4745
+ precice.setMeshVertices("FluidMesh", coords, vertexIDs);
4846

4947
- int displID = precice.getDataID("Displacements", meshID);
5048
- int forceID = precice.getDataID("Forces", meshID);
51-
52-
std::vector<double> forces(vertexSize*dim);
53-
std::vector<double> displacements(vertexSize*dim);
49+
- std::vector<double> forces(vertexSize*dim);
50+
- std::vector<double> displacements(vertexSize*dim);
51+
+ const double forceDim = participant.getDataDimensions("FluidMesh", "Forces")
52+
+ const double displDim = participant.getDataDimensions("FluidMesh", "Displacements")
53+
+ std::vector<double> forces(vertexSize*forceDimn);
54+
+ std::vector<double> displacements(vertexSize*displDim);
5455

5556
double solverDt; // solver timestep size
5657
double preciceDt; // maximum precice timestep size
5758
double dt; // actual time step size
5859

59-
- preciceDt = interface.initialize();
60-
61-
- if(interface.isActionRequired(cowid)){
62-
- interface.writeBlockVectorData(forceID, vertexSize, vertexIDs, forces.data());
63-
- interface.markActionFulfilled(cowid);
60+
- preciceDt = participant.initialize();
61+
- if (participant.isActionRequired(cowid)) {
62+
- participant.writeBlockVectorData(forceID, vertexSize, vertexIDs.data(), forces.data());
63+
- participant.markActionFulfilled(cowid);
6464
- }
65-
+ if(participant.requiresInitialData()){
65+
- participant.initializeData();
66+
+ if (participant.requiresInitialData()) {
6667
+ participant.writeData("FluidMesh", "Forces", vertexIDs, forces);
6768
+ }
68-
69-
- interface.initializeData();
7069
+ participant.initialize();
7170

72-
- while (interface.isCouplingOngoing()){
73-
- if(interface.isActionRequired(cowic)){
74-
+ while (participant.isCouplingOngoing()){
71+
while (participant.isCouplingOngoing()){
72+
- if(participant.isActionRequired(cowic)){
7573
+ if(participant.requiresWritingCheckpoint()){
7674
saveOldState(); // save checkpoint
77-
- interface.markActionFulfilled(cowic);
75+
- participant.markActionFulfilled(cowic);
7876
}
7977

8078
+ preciceDt = participant.getMaxTimeStepSize();
8179
solverDt = beginTimeStep(); // e.g. compute adaptive dt
8280
dt = min(preciceDt, solverDt);
8381

84-
- interface.readBlockVectorData(displID, vertexSize, vertexIDs, displacements.data());
82+
- participant.readBlockVectorData(displID, vertexSize, vertexIDs.data(), displacements.data());
8583
+ participant.readData("FluidMesh", "Displacements", vertexIDs, dt, displacements);
8684
setDisplacements(displacements);
8785
solveTimeStep(dt);
8886
computeForces(forces);
89-
- interface.writeBlockVectorData(forceID, vertexSize, vertexIDs, forces.data());
87+
- participant.writeBlockVectorData(forceID, vertexSize, vertexIDs.data(), forces.data());
9088
+ participant.writeData("FluidMesh", "Forces", vertexIDs, forces);
9189

92-
- preciceDt = interface.advance(dt);
90+
- preciceDt = participant.advance(dt);
9391
+ participant.advance(dt);
9492

95-
- if(interface.isActionRequired(coric)){ // timestep not converged
96-
+ if(participant.requiresReadingCheckpoint()){
93+
- if (participant.isActionRequired(coric)) { // timestep not converged
94+
+ if (participant.requiresReadingCheckpoint()) {
9795
reloadOldState(); // set variables back to checkpoint
98-
- interface.markActionFulfilled(coric);
96+
- participant.markActionFulfilled(coric);
9997
}
100-
else{ // timestep converged
98+
else { // timestep converged
10199
endTimeStep(); // e.g. update variables, increment time
102100
}
103101
}
104-
- interface.finalize(); // frees data structures and closes communication channels
105-
+ participant.finalize(); // frees data structures and closes communication channels
102+
participant.finalize(); // frees data structures and closes communication channels
106103

107-
- delete[] vertexIDs, forces, displacements;
108104
turnOffSolver();
109105
```
110106

0 commit comments

Comments
 (0)