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 1 commit
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
66 changes: 55 additions & 11 deletions examples/solverdummies/c/solverdummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

int main(int argc, char **argv)
{
Expand All @@ -10,9 +11,15 @@ int main(int argc, char **argv)
int solverProcessSize = 1;
int dimensions = -1;
double *vertex;
double *readData;
double *writeData;
int meshID = -1;
int dataID = -1;
int vertexID = -1;
int *vertexID;
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved
int N = 3;
int writeDataID = -1;
int readDataID = -1;


if (argc != 4) {
printf("Usage: ./solverdummy configFile solverName meshName\n\n");
Expand All @@ -26,7 +33,7 @@ int main(int argc, char **argv)
const char *configFileName = argv[1];
const char *participantName = argv[2];
const char *meshName = argv[3];

printf("DUMMY: Running solver dummy with preCICE config file \"%s\", participant name \"%s\", and mesh name \"%s\".\n",
configFileName, participantName, meshName);

Expand All @@ -37,37 +44,74 @@ 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("Forces",meshID);
readDataID = precicec_getDataID("Velocities",meshID);
}
if (strcmp(participantName,"SolverTwo") == 0){
writeDataID = precicec_getDataID("Velocities",meshID);
readDataID = precicec_getDataID("Forces",meshID);
}

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

for (int i = 0; i < N; i++){
for (int j = 0; j < dimensions; j++) {
vertex[j + N*i] = i;
readData[j + N*i] = i;
writeData[j + N*i] = i;
}
vertexID[i] = i;
printf("DUMMY: Vertex: %f, %f, %f \n",vertex[i*N + 0],vertex[i*N + 1],vertex[i*N + 2]);
printf("DUMMY: Read Data: %f, %f, %f \n",readData[i*N + 0],readData[i*N + 1],readData[i*N + 2]);
printf("DUMMY: Write Data: %f, %f, %f \n",writeData[i*N + 0],writeData[i*N + 1],writeData[i*N + 2]);
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved
}

vertexID = precicec_setMeshVertex(meshID, vertex);
precicec_setMeshVertices(meshID, N, vertex, vertexID);

free(vertex);

dt = precicec_initialize();

while (precicec_isCouplingOngoing()) {

if (precicec_isActionRequired(writeItCheckp)) {
printf("DUMMY: Writing iteration checkpoint");
precicec_writeBlockVectorData(writeDataID, N, vertexID, writeData);
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < N; i++){
printf("DUMMY: Write Data: %f, %f, %f \n",writeData[i*N + 0],writeData[i*N + 1],writeData[i*N + 2]);
}
printf("DUMMY: Writing iteration checkpoint \n");
precicec_markActionFulfilled(writeItCheckp);
}

dt = precicec_advance(dt);

if (precicec_isActionRequired(readItCheckp)) {
precicec_readBlockVectorData(readDataID, N, vertexID, readData);
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < N; i++){
printf("DUMMY: Read Data: %f, %f, %f \n",readData[i*N + 0],readData[i*N + 1],readData[i*N + 2]);
}
precicec_markActionFulfilled(readItCheckp);
printf("DUMMY: Reading iteration checkpoint");
printf("DUMMY: Reading iteration checkpoint \n");
} else {
printf("DUMMY: Advancing in time");
printf("DUMMY: Advancing in time \n");
}

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

}

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

return 0;
}
49 changes: 46 additions & 3 deletions examples/solverdummies/cpp/solverdummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,70 @@ int main(int argc, char **argv)

int meshID = interface.getMeshID(meshName);
int dimensions = interface.getDimensions();
std::string dataWriteName;
std::string dataReadName;
int N = 3; // Number of vertices

std::vector<double> vertex(dimensions, 0);
int vertexID = interface.setMeshVertex(meshID, vertex.data());
if (solverName == "SolverOne"){
dataWriteName="Forces";
dataReadName="Velocities";
}
if (solverName == "SolverTwo"){
dataReadName="Forces";
dataWriteName="Velocities";
}
const int readDataID = interface.getDataID(dataReadName,meshID);
const int writeDataID = interface.getDataID(dataWriteName,meshID);

double vertexPos[N * dimensions];
double readData[N * dimensions];
double writeData[N * dimensions];
int vertexIDs[N];
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved

for (int i = 0; i < N; i++){
for (int j = 0; j < dimensions; j++) {
vertexPos[j + N*i]=i;
readData[j + N*i] = i;
writeData[j + N*i] = i;
}
vertexIDs[i] = i;
std::cout << "DUMMY: Vertex: " << vertexPos[i*N + 0] << " ; " << vertexPos[i*N + 1] << " ; " << vertexPos[i*N + 2] << "\n";
std::cout << "DUMMY: Read Data: " << readData[i*N + 0] << " ; " << readData[i*N + 1] << " ; " << readData[i*N + 2] << "\n";
std::cout << "DUMMY: Write Data: " << writeData[i*N + 0] << " ; " << writeData[i*N + 1] << " ; " << writeData[i*N + 2] << "\n";
}
interface.setMeshVertices(meshID,N,vertexPos,vertexIDs);

double dt = interface.initialize();

while (interface.isCouplingOngoing()) {

if (interface.isActionRequired(actionWriteIterationCheckpoint())) {
interface.writeBlockVectorData(writeDataID,N,vertexIDs,writeData);
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < N; i++){
std::cout << "DUMMY: Write Data: " << writeData[i*N + 0] << " ; " << writeData[i*N + 1] << " ; " << writeData[i*N + 2] << "\n";
}
std::cout << "DUMMY: Writing iteration checkpoint\n";
interface.markActionFulfilled(actionWriteIterationCheckpoint());
}


dt = interface.advance(dt);

if (interface.isActionRequired(actionReadIterationCheckpoint())) {
std::cout << "DUMMY: Writing iteration checkpoint\n";
interface.readBlockVectorData(readDataID,N,vertexIDs,readData);
KyleDavisSA marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < N; i++){
std::cout << "DUMMY: Read Data: " << readData[i*N + 0] << " ; " << readData[i*N + 1] << " ; " << readData[i*N + 2] << "\n";
}
std::cout << "DUMMY: Reading iteration checkpoint\n";
interface.markActionFulfilled(actionReadIterationCheckpoint());
} else {
std::cout << "DUMMY: Advancing in time\n";
}

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

}

interface.finalize();
Expand Down
47 changes: 41 additions & 6 deletions examples/solverdummies/fortran/solverdummy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ PROGRAM main
IMPLICIT NONE
CHARACTER*512 :: config
CHARACTER*50 :: participantName, meshName, writeInitialData, readItCheckp, writeItCheckp
INTEGER :: rank, commsize, ongoing, dimensions, meshID, vertexID, bool
CHARACTER*50 :: DataReadName, DataWriteName
INTEGER :: rank, commsize, ongoing, dimensions, meshID, bool, N, i,j
INTEGER :: DataRead_ID, DataWrite_ID
REAL :: dtlimit
REAL, DIMENSION(:), ALLOCATABLE :: vertex
DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: vertex, DataWrite, DataRead
INTEGER, DIMENSION(:), ALLOCATABLE :: vertexID

! Constants in f90 have to be prefilled with blanks to be compatible with preCICE
writeInitialData(1:50)=' '
Expand All @@ -20,17 +23,43 @@ PROGRAM main
CALL getarg(2, participantName)
CALL getarg(3, meshName)

IF(participantName .eq. 'SolverOne') THEN
DataWriteName = 'Forces'
DataReadName = 'Velocities'
ENDIF
IF(participantName .eq. 'SolverTwo') THEN
DataWriteName = 'Velocities'
DataReadName = 'Forces'
ENDIF

rank = 0
commsize = 1
dtlimit = 1
N = 3 !Number of vertices
CALL precicef_create(participantName, config, rank, commsize)

! Allocate dummy mesh with only one vertex
CALL precicef_get_dims(dimensions)
ALLOCATE(vertex(dimensions))
vertex = 0
ALLOCATE(vertex(N*dimensions))
ALLOCATE(vertexID(N))
ALLOCATE(DataRead(N*dimensions))
ALLOCATE(DataWrite(N*dimensions))
CALL precicef_get_mesh_id(meshName, meshID)
CALL precicef_set_vertex(meshID, vertex, vertexID)
DEALLOCATE(vertex)

do i = 1,N,1
do j = 1,dimensions,1
vertex((i - 1)*dimensions + j ) = i-1
DataRead((i - 1)*dimensions + j ) = i-1
DataWrite((i - 1)*dimensions + j ) = i-1
enddo
vertexID(i) = i-1
enddo

CALL precicef_set_vertices(meshID, N, vertex, vertexID)
DEALLOCATE(vertex)

CALL precicef_get_data_id(DataReadName,meshID,DataRead_ID)
CALL precicef_get_data_id(DataWriteName,meshID,DataWrite_ID)

CALL precicef_initialize(dtlimit)

Expand All @@ -45,6 +74,7 @@ PROGRAM main

CALL precicef_action_required(writeItCheckp, bool)
IF (bool.EQ.1) THEN
CALL precicef_write_bvdata(DataWrite_ID, N, vertexID, DataWrite)
WRITE (*,*) 'DUMMY: Writing iteration checkpoint'
CALL precicef_mark_action_fulfilled(writeItCheckp)
ENDIF
Expand All @@ -54,11 +84,16 @@ PROGRAM main

CALL precicef_action_required(readItCheckp, bool)
IF (bool.EQ.1) THEN
CALL precicef_read_bvdata(DataRead_ID, N, vertexID, DataRead)
WRITE (*,*) 'DUMMY: Reading iteration checkpoint'
CALL precicef_mark_action_fulfilled(readItCheckp)
ELSE
WRITE (*,*) 'DUMMY: Advancing in time'
ENDIF

WRITE (*,*) 'DataRead: ', DataRead

DataWrite = DataRead + 1

ENDDO

Expand Down