<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi,</p>
<p>I'm new to PETSc, and I'm trying to learn how to use the DMPlex object. I've learned that you can assign labeled "fields" to a PETScSection/DMPlex, but I'm a bit lost as to how to access the data corresponding to each field.</p>
<p>The documentation suggests that data from different fields is stored in the same big vector, and you can access it with
<font face="Courier New, Courier, monospace">PetscSectionGetFieldOffset()</font>. I've tried this in the snippet below (using petsc4py)</p>
<p><font face="Courier New, Courier, monospace" size="2"># get points from the layout<br>
pstart, pend = section.getChart()<br>
<br>
# set vector values according to field<br>
arr = vec.getArray()<br>
<br>
for point in range(pstart, pend):<br>
print(point)<br>
offset_u = section.getFieldOffset(point, 0)<br>
offset_v = section.getFieldOffset(point, 1)<br>
offset_w = section.getFieldOffset(point, 2)<br>
<br>
print(offset_u, offset_v, offset_w)<br>
<br>
arr[offset_u] = 1<br>
<br>
for d in range(num_comp[1]):<br>
arr[offset_v + d] = 2<br>
<br>
for d in range(num_comp[2]):<br>
arr[offset_w + d] = 3</font><br>
</p>
<p>Unfortunately, this either this doesn't work or I'm not using it right. The offsets are often equal when they should be different for different variables, and they get larger than the number of points in the vector. Despite being recommended directly in
the documentation, there aren't any examples of it being used in context either.<br>
</p>
<p>A previous entry in the mailing list suggests using <font face="Courier New, Courier, monospace">
DMCreateSubDM()</font> to instead split the DM (and the vectors, in the process) up by field. There's also
<font face="Courier New, Courier, monospace">DMCreateFieldDecomposition()</font>, which appears to do something similar.</p>
<p>Is there a "canonical" way to access different fields? Does anyone have some simple examples of different field variables being declared, allocated, set, and accessed? I'm still new enough that I'm not even sure what questions to ask at this point, but any
help would be appreciated.</p>
<p>Thank you,</p>
<p>Andrea Irwin<br>
</p>
</body>
</html>