Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 64 additions & 38 deletions examples/partitioned-heat-conduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/

#include <gismo.h>
#include <fstream>
#include <iterator>
#include <gsPreCICE/gsPreCICE.h>
#include <gsPreCICE/gsPreCICEFunction.h>

Expand All @@ -37,6 +39,19 @@ int main(int argc, char *argv[])
cmd.addInt("s","side", "Patchside of interface: 0 (Dirichlet), 1 (Neumann)", side);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }

auto configContains = [](const std::string & fileName, const std::string & needle) -> bool
{
std::ifstream config(fileName.c_str());
GISMO_ASSERT(config.good(), "No precice config file has been defined");
const std::string contents((std::istreambuf_iterator<char>(config)),
std::istreambuf_iterator<char>());
return contents.find(needle) != std::string::npos;
};

const bool useDirectMeshAccess =
configContains(precice_config, "direct-access=\"true\"") ||
configContains(precice_config, "api-access=\"true\"");

//! [Read input file]

gsMultiPatch<> patches;
Expand Down Expand Up @@ -151,9 +166,9 @@ int main(int argc, char *argv[])
// Register local mesh coordinates
interface.addMesh(localMeshName, xy);

// Define access region for the received mesh in serial mode
// Use a generous bounding box pattern seen in other examples
if (useDirectMeshAccess)
{
// Restrict mesh access to the remote interface only when the config enables API access.
gsMatrix<> bbox(rows, 2);
bbox.col(0).setConstant(-1e300);
bbox.col(1).setConstant( 1e300);
Expand All @@ -166,19 +181,22 @@ int main(int argc, char *argv[])

real_t precice_dt = interface.initialize();

// Direct-access: fetch partner mesh vertex IDs and coordinates.
// Evaluate quantities at partner coordinates (no reordering needed).
gsVector<index_t> remoteIDs;
gsMatrix<> remoteCoords;
interface.getMeshVertexIDsAndCoordinates(remoteMeshName, remoteIDs, remoteCoords);
// Invert partner physical coords to param coords on our coupling patch
gsMatrix<> uvRemote;
patches.patch(couplingInterface.patch).invertPoints(remoteCoords, uvRemote, 1e-10);
// Ensure boundary parameter is exact for evalBdr
const int bdir = couplingInterface.side().direction();
const real_t bpar = couplingInterface.side().parameter();
for (index_t i = 0; i != uvRemote.cols(); ++i)
uvRemote(bdir, i) = bpar;
if (useDirectMeshAccess)
{
// Direct-access: fetch partner mesh vertex IDs and coordinates.
// Evaluate quantities at partner coordinates (no reordering needed).
interface.getMeshVertexIDsAndCoordinates(remoteMeshName, remoteIDs, remoteCoords);
patches.patch(couplingInterface.patch).invertPoints(remoteCoords, uvRemote, 1e-10);

// Ensure boundary parameter is exact for evalBdr.
const int bdir = couplingInterface.side().direction();
const real_t bpar = couplingInterface.side().parameter();
for (index_t i = 0; i != uvRemote.cols(); ++i)
uvRemote(bdir, i) = bpar;
}

// ----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -260,23 +278,27 @@ int main(int argc, char *argv[])
result(0,k) = tmp2.at(0);
}
}
// Build values at partner coordinates (order matches remoteIDs)
result.resize(1, uvRemote.cols());
for (index_t k=0; k!=uvRemote.cols(); ++k)
if (useDirectMeshAccess)
{
if (side==0) // Dirichlet writes flux
{
tmp2 = ev.evalBdr( - k_temp * (igrad(u_sol, G) * nv(G).normalized()), uvRemote.col(k), couplingInterface);
result(0,k) = tmp2.at(0);
}
else // Neumann writes temperature
// Build values at partner coordinates (order matches remoteIDs).
result.resize(1, uvRemote.cols());
for (index_t k=0; k!=uvRemote.cols(); ++k)
{
tmp2 = ev.evalBdr(u_sol, uvRemote.col(k), couplingInterface);
result(0,k) = tmp2.at(0);
if (side==0) // Dirichlet writes flux
{
tmp2 = ev.evalBdr( - k_temp * (igrad(u_sol, G) * nv(G).normalized()), uvRemote.col(k), couplingInterface);
result(0,k) = tmp2.at(0);
}
else // Neumann writes temperature
{
tmp2 = ev.evalBdr(u_sol, uvRemote.col(k), couplingInterface);
result(0,k) = tmp2.at(0);
}
}
interface.writeData(remoteMeshName, (side==0 ? fluxName : tempName), remoteIDs, result);
}
// Write on partner mesh using its vertex IDs (direct-access config)
interface.writeData(remoteMeshName, (side==0 ? fluxName : tempName), remoteIDs, result);
else
interface.writeData(localMeshName, (side==0 ? fluxName : tempName), xy, result);
}

// Initialize the RHS for assembly
Expand Down Expand Up @@ -372,23 +394,27 @@ int main(int argc, char *argv[])
result(0,k) = tmp.at(0);
}
}
// Build values at partner coordinates (order matches remoteIDs)
result.resize(1, uvRemote.cols());
for (index_t k=0; k!=uvRemote.cols(); ++k)
if (useDirectMeshAccess)
{
if (side==0) // Dirichlet writes flux
{
tmp = ev.evalBdr( - k_temp * (igrad(u_sol, G) * nv(G).normalized()), uvRemote.col(k), couplingInterface);
result(0,k) = tmp.at(0);
}
else // Neumann writes temperature
// Build values at partner coordinates (order matches remoteIDs).
result.resize(1, uvRemote.cols());
for (index_t k=0; k!=uvRemote.cols(); ++k)
{
tmp = ev.evalBdr(u_sol, uvRemote.col(k), couplingInterface);
result(0,k) = tmp.at(0);
if (side==0) // Dirichlet writes flux
{
tmp = ev.evalBdr( - k_temp * (igrad(u_sol, G) * nv(G).normalized()), uvRemote.col(k), couplingInterface);
result(0,k) = tmp.at(0);
}
else // Neumann writes temperature
{
tmp = ev.evalBdr(u_sol, uvRemote.col(k), couplingInterface);
result(0,k) = tmp.at(0);
}
}
interface.writeData(remoteMeshName, (side==0 ? fluxName : tempName), remoteIDs, result);
}
// Write on partner mesh using its vertex IDs (direct-access config)
interface.writeData(remoteMeshName, (side==0 ? fluxName : tempName), remoteIDs, result);
else
interface.writeData(localMeshName, (side==0 ? fluxName : tempName), xy, result);

// do the coupling
precice_dt = interface.advance(dt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<participant name="Dirichlet">
<provide-mesh name="Flux-Control-Point-Mesh" />
<provide-mesh name="Flux-Knot-Mesh" />
<receive-mesh name="Geometry-Control-Point-Mesh" from="Neumann" direct-access="true"/>
<receive-mesh name="Geometry-Control-Point-Mesh" from="Neumann" api-access="true"/>
<receive-mesh name="Geometry-Knot-Mesh" from="Neumann" />
<read-data name="Temperature-Data" mesh="Geometry-Control-Point-Mesh" />
<write-data name="Flux-Control-Point-Data" mesh="Flux-Control-Point-Mesh" />
Expand All @@ -46,7 +46,7 @@
<participant name="Neumann">
<provide-mesh name="Geometry-Control-Point-Mesh" />
<provide-mesh name="Geometry-Knot-Mesh" />
<receive-mesh name="Flux-Control-Point-Mesh" from="Dirichlet" direct-access="true"/>
<receive-mesh name="Flux-Control-Point-Mesh" from="Dirichlet" api-access="true"/>
<receive-mesh name="Flux-Knot-Mesh" from="Dirichlet" />
<read-data name="Flux-Control-Point-Data" mesh="Flux-Control-Point-Mesh" />
<write-data name="Temperature-Data" mesh="Geometry-Control-Point-Mesh" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

<participant name="Dirichlet">
<provide-mesh name="Dirichlet-Mesh" />
<receive-mesh name="Neumann-Mesh" from="Neumann" direct-access="true" />
<receive-mesh name="Neumann-Mesh" from="Neumann" api-access="true" />
<write-data name="Heat-Flux" mesh="Neumann-Mesh" />
<read-data name="Temperature" mesh="Dirichlet-Mesh" />
</participant>

<participant name="Neumann">
<provide-mesh name="Neumann-Mesh" />
<receive-mesh name="Dirichlet-Mesh" from="Dirichlet" direct-access="true" />
<receive-mesh name="Dirichlet-Mesh" from="Dirichlet" api-access="true" />
<write-data name="Temperature" mesh="Dirichlet-Mesh" />
<read-data name="Heat-Flux" mesh="Neumann-Mesh" />
</participant>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<participant name="Fluid">
<provide-mesh name="ForceControlPointMesh" />
<provide-mesh name="ForceKnotMesh" />
<receive-mesh name="GeometryControlPointMesh" from="Solid" direct-access="true"/>
<receive-mesh name="GeometryControlPointMesh" from="Solid" api-access="true"/>
<receive-mesh name="GeometryKnotMesh" from="Solid" />
<read-data name="GeometryControlPointData" mesh="GeometryControlPointMesh" />
<!-- <read-data name="GeometryKnotData" mesh="GeometryKnotMesh" />-->
Expand All @@ -48,7 +48,7 @@
<participant name="Solid">
<provide-mesh name="GeometryControlPointMesh" />
<provide-mesh name="GeometryKnotMesh" />
<receive-mesh name="ForceControlPointMesh" from="Fluid" direct-access="true"/>
<receive-mesh name="ForceControlPointMesh" from="Fluid" api-access="true"/>
<receive-mesh name="ForceKnotMesh" from="Fluid" />
<!-- <read-data name="ForceKnotMeshData" mesh="ForceKnotMesh" />-->
<read-data name="ForceControlPointData" mesh="ForceControlPointMesh" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</mesh>

<participant name="Fluid">
<receive-mesh name="ForceMesh" from="Solid" direct-access="false"/>
<receive-mesh name="KnotMesh" from="Solid" direct-access="false"/>
<receive-mesh name="ControlPointMesh" from="Solid" direct-access="true"/>
<receive-mesh name="ForceMesh" from="Solid" api-access="false"/>
<receive-mesh name="KnotMesh" from="Solid" api-access="false"/>
<receive-mesh name="ControlPointMesh" from="Solid" api-access="true"/>
<read-data name="ControlPointData" mesh="ControlPointMesh" />
<write-data name="ForceData" mesh="ForceMesh" />
</participant>
Expand Down
Loading