Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifies solverdummy to include data transfer #750

Merged
merged 8 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 56 additions & 13 deletions examples/solverdummies/c/solverdummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
double dt = 0.0;
int solverProcessIndex = 0;
int solverProcessSize = 1;
int dimensions = -1;
double *vertex;
double *vertices;
double *readData;
double *writeData;
int meshID = -1;
int dataID = -1;
int vertexID = -1;
int *vertexIDs;
int numberOfVertices = 3;
int writeDataID = -1;
int readDataID = -1;


if (argc != 4) {
printf("Usage: ./solverdummy configFile solverName meshName\n\n");
Expand All @@ -37,37 +44,73 @@ int main(int argc, char **argv)

meshID = precicec_getMeshID(meshName);

dimensions = precicec_getDimensions();
vertex = malloc(dimensions * sizeof(double));
if (strcmp(participantName,"SolverOne") == 0){
writeDataID = precicec_getDataID("dataOne",meshID);
readDataID = precicec_getDataID("dataTwo",meshID);
}
if (strcmp(participantName,"SolverTwo") == 0){
writeDataID = precicec_getDataID("dataTwo",meshID);
readDataID = precicec_getDataID("dataOne",meshID);
}
MakisH marked this conversation as resolved.
Show resolved Hide resolved

for (int i = 0; i < dimensions; i++) {
vertex[i] = 0.0;
dimensions = precicec_getDimensions();
vertices = malloc(numberOfVertices * dimensions * sizeof(double));
readData = malloc(numberOfVertices * dimensions * sizeof(double));
writeData = malloc(numberOfVertices * dimensions * sizeof(double));
vertexIDs = malloc(numberOfVertices * sizeof(int));

for (int i = 0; i < numberOfVertices; i++){
for (int j = 0; j < dimensions; j++) {
vertices[j + numberOfVertices*i] = i;
readData[j + numberOfVertices*i] = i;
writeData[j + numberOfVertices*i] = i;
}
}

vertexID = precicec_setMeshVertex(meshID, vertex);
free(vertex);
precicec_setMeshVertices(meshID, numberOfVertices, vertices, vertexIDs);

free(vertices);

dt = precicec_initialize();

while (precicec_isCouplingOngoing()) {

if (precicec_isActionRequired(writeItCheckp)) {
printf("DUMMY: Writing iteration checkpoint");
printf("DUMMY: Writing iteration checkpoint \n");
precicec_markActionFulfilled(writeItCheckp);
}

if(precicec_isReadDataAvailable)
{
precicec_readBlockVectorData(readDataID, numberOfVertices, vertexIDs, readData);
}

for (int i = 0; i < numberOfVertices*dimensions; i++){
writeData[i] = readData[i] + 1;
}

if(precicec_isWriteDataRequired(dt))
{
precicec_writeBlockVectorData(writeDataID, numberOfVertices, vertexIDs, writeData);
}

dt = precicec_advance(dt);

if (precicec_isActionRequired(readItCheckp)) {
printf("DUMMY: Reading iteration checkpoint \n");
precicec_markActionFulfilled(readItCheckp);
printf("DUMMY: Reading iteration checkpoint");
} else {
printf("DUMMY: Advancing in time");
}
else{
printf("DUMMY: Advancing in time \n");
}

}

precicec_finalize();
printf("DUMMY: Closing C solver dummy...");
free(writeData);
free(readData);
free(vertexIDs);
printf("DUMMY: Closing C solver dummy... \n");

return 0;
}
48 changes: 43 additions & 5 deletions examples/solverdummies/cpp/solverdummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,37 @@ int main(int argc, char **argv)

SolverInterface interface(solverName, configFileName, commRank, commSize);

int meshID = interface.getMeshID(meshName);
int dimensions = interface.getDimensions();
int meshID = interface.getMeshID(meshName);
int dimensions = interface.getDimensions();
std::string dataWriteName;
std::string dataReadName;
int numberOfVertices = 3;

if (solverName == "SolverOne") {
dataWriteName = "dataOne";
dataReadName = "dataTwo";
}
if (solverName == "SolverTwo") {
dataReadName = "dataOne";
dataWriteName = "dataTwo";
}
const int readDataID = interface.getDataID(dataReadName, meshID);
const int writeDataID = interface.getDataID(dataWriteName, meshID);

std::vector<double> readData(numberOfVertices * dimensions);
std::vector<double> writeData(numberOfVertices * dimensions);
std::vector<double> vertices(numberOfVertices * dimensions);
std::vector<int> vertexIDs(numberOfVertices);

for (int i = 0; i < numberOfVertices; i++) {
for (int j = 0; j < dimensions; j++) {
vertices[j + numberOfVertices * i] = i;
readData[j + numberOfVertices * i] = i;
writeData[j + numberOfVertices * i] = i;
}
}

std::vector<double> vertex(dimensions, 0);
int vertexID = interface.setMeshVertex(meshID, vertex.data());
interface.setMeshVertices(meshID, numberOfVertices, vertices.data(), vertexIDs.data());

double dt = interface.initialize();

Expand All @@ -45,10 +71,22 @@ int main(int argc, char **argv)
interface.markActionFulfilled(actionWriteIterationCheckpoint());
}

if (interface.isReadDataAvailable()) {
interface.readBlockVectorData(readDataID, numberOfVertices, vertexIDs.data(), readData.data());
}

for (int i = 0; i < numberOfVertices * dimensions; i++) {
writeData[i] = readData[i] + 1;
}

if (interface.isWriteDataRequired(dt)) {
interface.writeBlockVectorData(writeDataID, numberOfVertices, vertexIDs.data(), writeData.data());
}

dt = interface.advance(dt);

if (interface.isActionRequired(actionReadIterationCheckpoint())) {
std::cout << "DUMMY: Writing iteration checkpoint\n";
std::cout << "DUMMY: Reading iteration checkpoint\n";
interface.markActionFulfilled(actionReadIterationCheckpoint());
} else {
std::cout << "DUMMY: Advancing in time\n";
Expand Down
83 changes: 66 additions & 17 deletions examples/solverdummies/fortran/solverdummy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ PROGRAM main
IMPLICIT NONE
CHARACTER*512 :: config
CHARACTER*50 :: participantName, meshName, writeInitialData, readItCheckp, writeItCheckp
INTEGER :: rank, commsize, ongoing, dimensions, meshID, vertexID, bool
REAL :: dtlimit
REAL, DIMENSION(:), ALLOCATABLE :: vertex

CHARACTER*50 :: readDataName, writeDataName
INTEGER :: rank, commsize, ongoing, dimensions, meshID, bool, numberOfVertices, i,j
INTEGER :: readDataID, writeDataID
REAL :: dt
DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: vertices, writeData, readData
INTEGER, DIMENSION(:), ALLOCATABLE :: vertexIDs

! Constants in f90 have to be prefilled with blanks to be compatible with preCICE
writeInitialData(1:50)=' '
readItCheckp(1:50)=' '
writeItCheckp(1:50)=' '

CALL precicef_action_write_initial_data(writeInitialData)
CALL precicef_action_read_iter_checkp(readItCheckp)
CALL precicef_action_write_iter_checkp(writeItCheckp)
Expand All @@ -20,19 +23,45 @@ PROGRAM main
CALL getarg(2, participantName)
CALL getarg(3, meshName)

IF(participantName .eq. 'SolverOne') THEN
writeDataName = 'dataOne'
readDataName = 'dataTwo'
ENDIF
IF(participantName .eq. 'SolverTwo') THEN
writeDataName = 'dataTwo'
readDataName = 'dataOne'
ENDIF

rank = 0
commsize = 1
dt = 1
numberOfVertices = 3
CALL precicef_create(participantName, config, rank, commsize)

! Allocate dummy mesh with only one vertex
! Allocate dummy mesh with only one vertex
CALL precicef_get_dims(dimensions)
ALLOCATE(vertex(dimensions))
vertex = 0
ALLOCATE(vertices(numberOfVertices*dimensions))
ALLOCATE(vertexIDs(numberOfVertices))
ALLOCATE(readData(numberOfVertices*dimensions))
ALLOCATE(writeData(numberOfVertices*dimensions))
CALL precicef_get_mesh_id(meshName, meshID)
CALL precicef_set_vertex(meshID, vertex, vertexID)
DEALLOCATE(vertex)

CALL precicef_initialize(dtlimit)

do i = 1,numberOfVertices,1
do j = 1,dimensions,1
vertices((i - 1)*dimensions + j ) = i-1
readData((i - 1)*dimensions + j ) = i-1
writeData((i - 1)*dimensions + j ) = i-1
enddo
vertexIDs(i) = i-1
enddo

CALL precicef_set_vertices(meshID, numberOfVertices, vertices, vertexIDs)
DEALLOCATE(vertices)

CALL precicef_get_data_id(readDataName,meshID,readDataID)
CALL precicef_get_data_id(writeDataName,meshID,writeDataID)

CALL precicef_initialize(dt)

CALL precicef_is_action_required(writeInitialData, bool)
IF (bool.EQ.1) THEN
Expand All @@ -44,13 +73,27 @@ PROGRAM main
DO WHILE (ongoing.NE.0)

CALL precicef_is_action_required(writeItCheckp, bool)

IF (bool.EQ.1) THEN
WRITE (*,*) 'DUMMY: Writing iteration checkpoint'
CALL precicef_mark_action_fulfilled(writeItCheckp)
ENDIF

CALL precicef_advance(dtlimit)
CALL precicef_is_coupling_ongoing(ongoing)
CALL precicef_is_read_data_available(bool)
IF (bool.EQ.1) THEN
CALL precicef_read_bvdata(readDataID, numberOfVertices, vertexIDs, readData)
ENDIF

WRITE (*,*) 'readData: ', readData

writeData = readData + 1

CALL precicef_is_write_data_required(dt, bool)
IF (bool.EQ.1) THEN
CALL precicef_write_bvdata(writeDataID, numberOfVertices, vertexIDs, writeData)
ENDIF

CALL precicef_advance(dt)

CALL precicef_is_action_required(readItCheckp, bool)
IF (bool.EQ.1) THEN
Expand All @@ -59,10 +102,16 @@ PROGRAM main
ELSE
WRITE (*,*) 'DUMMY: Advancing in time'
ENDIF


CALL precicef_is_coupling_ongoing(ongoing)

ENDDO

CALL precicef_finalize()
WRITE (*,*) 'DUMMY: Closing Fortran solver dummy...'

END PROGRAM
DEALLOCATE(writeData)
DEALLOCATE(readData)
DEALLOCATE(vertexIDs)

END PROGRAM
56 changes: 23 additions & 33 deletions examples/solverdummies/precice-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,50 @@
<precice-configuration>

<log>
<sink type="stream" output="stdout" filter= "%Severity% > debug" format="preCICE:%ColorizedSeverity% %Message%" enabled="true" />
<sink type="stream" output="stdout" filter= "%Severity% > debug" format="preCICE:%ColorizedSeverity% %Message%" enabled="true" />
</log>

<solver-interface dimensions="2" >
<data:vector name="Forces" />
<data:vector name="Velocities" />
<solver-interface dimensions="3" >

<data:vector name="dataOne" />
<data:vector name="dataTwo" />

<mesh name="MeshOne">
<use-data name="Forces" />
<use-data name="Velocities" />
<use-data name="dataOne" />
<use-data name="dataTwo" />
</mesh>

<mesh name="MeshTwo">
<use-data name="Forces" />
<use-data name="Velocities" />
<use-data name="dataOne" />
<use-data name="dataTwo" />
</mesh>

<participant name="SolverOne">
<use-mesh name="MeshOne" provide="yes"/>
<write-data name="Forces" mesh="MeshOne" />
<read-data name="Velocities" mesh="MeshOne" />
<write-data name="dataOne" mesh="MeshOne" />
<read-data name="dataTwo" mesh="MeshOne" />
</participant>

<participant name="SolverTwo">
<use-mesh name="MeshOne" from="SolverOne"/>
<use-mesh name="MeshTwo" provide="yes"/>
<mapping:nearest-neighbor direction="write" from="MeshTwo" to="MeshOne" constraint="conservative"/>
<mapping:nearest-projection direction="read" from="MeshOne" to="MeshTwo" constraint="consistent" />
<write-data name="Velocities" mesh="MeshTwo" />
<read-data name="Forces" mesh="MeshTwo" />
<mapping:nearest-neighbor direction="write" from="MeshTwo" to="MeshOne" constraint="conservative"/>
<mapping:nearest-neighbor direction="read" from="MeshOne" to="MeshTwo" constraint="consistent" />
<write-data name="dataTwo" mesh="MeshTwo" />
<read-data name="dataOne" mesh="MeshTwo" />
</participant>

<m2n:sockets from="SolverOne" to="SolverTwo"/>

<coupling-scheme:serial-implicit>
<participants first="SolverOne" second="SolverTwo" />
<max-time-windows value="10" />
<time-window-size value="1.0" />
<max-iterations value="3" />
<min-iteration-convergence-measure min-iterations="5" data="Forces" mesh="MeshOne"/>
<exchange data="Forces" mesh="MeshOne" from="SolverOne" to="SolverTwo" />
<exchange data="Velocities" mesh="MeshOne" from="SolverTwo" to="SolverOne"/>
</coupling-scheme:serial-implicit>

<!--
<coupling-scheme:serial-explicit>
<participants first="SolverOne" second="SolverTwo" />
<max-time-windows value="10" />
<coupling-scheme:serial-implicit>
<participants first="SolverOne" second="SolverTwo" />
<max-time-windows value="2" />
<time-window-size value="1.0" />
<exchange data="Forces" mesh="MeshOne" from="SolverOne" to="SolverTwo" />
<exchange data="Velocities" mesh="MeshOne" from="SolverTwo" to="SolverOne"/>
</coupling-scheme:serial-explicit>
-->
<max-iterations value="2" />
<min-iteration-convergence-measure min-iterations="5" data="dataOne" mesh="MeshOne"/>
<exchange data="dataOne" mesh="MeshOne" from="SolverOne" to="SolverTwo" />
<exchange data="dataTwo" mesh="MeshOne" from="SolverTwo" to="SolverOne"/>
</coupling-scheme:serial-implicit>
</solver-interface>

</precice-configuration>