Replies: 5 comments 4 replies
-
If you can't figure this out, consider attaching a Comsol model to your question, for demonstration purposes. Or refer to the demo model from the tutorial. Yes, this is definitely possible if you go through the Comsol API, via the |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer @john-hen. Consider the attached model. What I'm trying to do is pretty much the same as the 1D plot group, i.e. extract the If it's possible to use Otherwise, I was experimenting with a java method within Comsol's Application Builder and it's possible to extract velocities at a given point using the NumericalFeature newEval = model.result().numerical().create("newEval", "EvalGlobal");
newEval.set("expr", "at2(0.010,0.014,spf.U)");
newEval.set("data", "dset1");
double[][] data = newEval.getReal();
debugLog(data);
model.result().numerical().remove("newEval"); which gives
But again I don't know how to reference the desired boundary instead of a point. Also, translating this to Hope it provides more details about my question :) |
Beta Was this translation helpful? Give feedback.
-
There are probably a number of ways to do this. For example, the Comsol API also lets us export the data associated with a specific plot. But it seems more straightforward to me to define an edge dataset and get to that data directly. There may be a way to use a "linear extrusion" operator, or some such operator, so that we could just call MPh's Instead, we can use an Consider this script: import mph
from numpy import array
client = mph.start()
model = client.load('extract_values.mph')
# Create edge dataset and select boundary number 4.
edge = (model/'datasets').create('Edge2D')
edge.select(4)
# Retrieve the data for each field.
interp = (model/'evaluations').create('Interp')
interp.property('data', edge)
interp.property('solnum', 1) # Only first time step (inner solution).
interp.property('expr', 'r')
interp.property('unit', 'mm')
r = array(interp.java.getReal()).squeeze()
interp.property('expr', 'z')
interp.property('unit', 'mm')
z = array(interp.java.getReal()).squeeze()
interp.property('expr', 'spf.U')
interp.property('unit', 'mm/s')
U = array(interp.java.getReal()).squeeze()
# Print some stats.
print(f'Retrieved {len(r)} values.')
print(f'r = {r.min()} ... {r.max()} mm')
print(f'z = {z.min()} ... {z.max()} mm')
print(f'U = {U.min()} ... {U.max()} mm/s') Which outputs:
|
Beta Was this translation helpful? Give feedback.
-
Sorry for the late reply @john-hen and many thanks for the useful answer. I've been testing it and it works pretty decently, however I have a follow-up question: If I the I tried something like: edge1 = (model1/'datasets/Edge 2D 1')
interp1 = (model1/'evaluations/Interp')
edge.select(4)
interp1.property('data', edge1)
interp1.property('solnum', 2)
interp1.property('expr', 'r')
interp1.property('unit', 'mm')
out = array(interp1.java.getReal()).squeeze() Which gives the error ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell 9 line 4
[2] interp1 = (model1/'evaluations/Interp')
[3] edge1.select(4)
----> [4] interp1.property('data', edge1)
[5] interp1.property('solnum', 2)
[6] interp1.property('expr', 'r')
File ..., in Node.property(self, name, value)
[394] return get(self.java, name)
[395] else:
--> [396] self.java.set(name, cast(value))
AttributeError: 'NoneType' object has no attribute 'set' Can you enlighten me on how to properly refer to existing datasets in this case? |
Beta Was this translation helpful? Give feedback.
-
How to export the concentration information on an edge RuntimeError: Dataset "Edge 2D 1" does not refer to a solution. |
Beta Was this translation helpful? Give feedback.
-
Simply put, how to extract the coordinates and an expression evaluated at a given boundary directly from the
model
attribute?More specifically, consider a given boundary of a 2D-axisymmetric component. I want to extract its coordinates and also an expression, say
(r,z)
andcomp1.T
.I haven't found a direct MPh function to do it, but it seems to be possible via the
.java
attribute. Unfortunately, I couldn't find the answer either.From comsol's programming reference manual, it seems that the
numerical()
attribute could do the trick, e.g.:model.result().numerical(<ftag>).getData();
, though it's not clear to me how to reference the desired boundary and expression.Does anyone happen to know a way to approach this?
Beta Was this translation helpful? Give feedback.
All reactions