Dear Andreas,
2011/4/21 Andreas Kloeckner <lists(a)informa.tiker.net>:
>
> What you want to do is perfectly possible, just not in the way you
> think. :) First of all, each "Field" necessarily has to correspond to a
> scalar field. *But* you are free to make these variables up as you
> please, as long as you provide values for them at evaluation time. So
> instead of Field('material').mu, say Field('mu'), and then, at
> evaluation time, say
>
> op(arg1=value, **kwargs)
>
> where kwargs is a dictionary of these values. Fortunately, Python is
> flexible enough that you can easily make such a dictionary from whatever
> source, be it an object or whatever else.
>
> One caveat: Getting these variables into fluxes might be a bit
> cumbersome, as these are applied to a vector of scalar fields--thus
> each of them must have a numerical index, so you need a convention for
> packing them into a vector.
>
Thank you very much for those informations. I think I need a few more
details so I can make my code work. I have tried different
possibilities but I'm afraid I'm still thinking the wrong way, so,
there are things I still don't understand...
I have objects (material1, material2...) which contain the constants
(material1.C, material2.C, material1.mu, etc.) that I need to access
when calculating the fluxes. C is a 6x6 matrix.
1) Do I need to create a space-dependent function for each constant
(I'd like not to), or can I rely on Field() to make only "a reference
to the material object" be space-dependent?
i.e. Can I use this?
material_elements = {}
for key in materials.keys():
material_elements[key] = set(mesh_data.tag_to_elements[key])
def mat_val(x, el):
for key in materials.keys():
if el in material_elements[key]:
return key
raise ValueError, "Material not found for this element"
op = MyOperator(dim=dim,
mat_val = make_tdep_given(mat_val),
materials = materials,
...
)
And, then, materials[material].mu, materials[material].C
Or do I need a C_val, mu_val, etc.?
2) I have packed this in a vector, so, I have:
def __init__(self,
dim,
mat_val,
materials,
...
):
self.mat_val = mat_val
...
# In rsh:
constants = self.mat_val
return compiled_op_template(q=q,constants=constants,**extra_kwargs)
# ^^^^^ Is this right? I am not touching extra_kwargs...
# In op_template:
q = make_vector_field('q', dim+self.dimF[dim])
constants = make_vector_field('constants', 1)
material = constants
# In the flux calculation, I try to access materials[material].mu but I get:
TypeError: unhashable type: 'numpy.ndarray'
# Probably because:
print material
# Prints
[constants[0]]
# However, if I replace self.materials[material].mu by
self.materials[material[0]].mu, I get:
KeyError: Subscript(Variable('constants'), 0)
What am I doing wrong?
3) I have read http://wiki.tiker.net/Hedge/HowTo/DealingwithOperators
but I don't understand when exactly I have to use Field() and when I
can pass the values in function calls...
I'm sorry to disturb you about this, but I have spent a full week on
this without managing to have it work... I feel lost :)
Thanks in advance
Best regards
--
Peter Potrowl
Hello all,
I'm using the CNS operator in hedge and I'm playing around with the
conduction operators in there. Last time we e-mailed about this, which was a
long time ago, you mentioned that I'd have to play around to give the walls
a defined temperature.
I'm wondering how exactly I would do that. Looking inside of the
gas_dynamics __init__.py, there's not anything that jumps out to me where I
could play around with what hedge does for boundary conditions, not even for
the velocity BCs, much less setting a wall temperature. Am I looking at the
wrong file? I'm hoping that I can set separate wall temperatures for
different wall sections, similar to how it's done for the velocity BCs?
I also checked out the heat.py model, as well as the heat.py example; the BC
tags there are Dirichlet and Neumann of course, but I don't see those tags
in the gas_dynamics operator so I don't think I can use them to tag the
walls of my CNS example. I'd appreciate any help :)
Thanks,
Daniel Gempesaw
Dear M. Klockner
I think I found a bug in:
http://git.tiker.net/hedge.git/blob/ee22cbe6493b7369d49f8bbe821af6b8636e340…
dimension, number, name = next_line.split()
When I parse the following file:
$MeshFormat
2.1 0 8
$EndMeshFormat
$PhysicalNames
3
0 1 "Source"
0 2 "Receiver"
2 3 "My Surface"
$EndPhysicalNames
$Nodes
2254
1 0 0 0
...
$EndNodes
$Elements
4322
1 15 3 1 6 0 5
...
$EndElements
I get the error:
ValueError: too many values to unpack
because this:
2 3 "My Surface"
is splitted as:
['2', '3', '"My', 'Surface"']
So, I suggest that the line should be replaced with:
dimension, number, name = next_line.split(' ', 2)
This way, it is correctly split as:
['2', '3', '"My Surface"']
I also have a question concerning operators: I would like to deal with
hererogeneous materials. I had a look at
http://forge.tiker.net/p/hedge/source/commit/5477a22e0efde599d8a0fec26427ee…
but I don't want to define the variable constants like:
epsilon = Field("epsilon")
mu = Field("mu")
etc
because I have tens of them (matrices, actually).
Is there a way to pass a reference to an global object in an operator,
like mu=Field('material').mu? or a string, like
mu=self.materials[Field('material')].mu
Or to define global constants and access them dynamically according to
the element?
I tried several ways, including tags, but I can't find a good method for this...
Can you give me some advice, please?
Thanks in advance
Best regards
--
Peter Potrowl
2011/4/19 Xueyu Zhu <zhucer2003(a)gmail.com>:
>
> I guess you don't have to create the coeff func for each element. you might
> do this
>
> def mu_coeff(x,el)
> if el.tag = "material1"
> return mu1(x) # where you define mu1 somehere
> elif el.tag = "material2"
> return mu2(x)
>
> I am not sure if that's what you want? maybe you can give an example about
> what your function of mu looks like?
>
Well, mu is a constant (float) for each material. I have a variable
number of materials.
I have tens of constants like mu (C (6*6 matrix), rho, and a lot of
other ones, which are the properties of the materials). I already have
objects (material1, material2...) which contain those constants
(material1.C, material2.C, material1.mu, etc.).
I don't want to create a function for each constant (mu, C, rho...)
because there are a lot of them and I want to be able to add new
constants without changing this part of the code.
I would like to do something like this:
materials = { 'material1': material1, 'material2': material2... }
def material(x,el)
return materials[el.tag]
mu = material(x, el).mu
My problem is that:
* I don't have a direct access to material(x, el) from the operator
(as far as I know, but I might be wrong)
* If I do something like kwargs["material"] =
self.material.volume_interpolant(t, discr) (as for source_u in
http://git.tiker.net/hedge.git/blob/HEAD:/hedge/models/wave.py ), I
can't use Field('material').mu because Field('material') is just a
placeholder, not an object...
Any ideas?
Best regards
--
Peter Potrowl
Hi,
I just installed and configured hedge plus dependencies (all from
the repositories). It was not a straight walk-through mainly
because I insisted on installing it in my $HOME, but I succeeded
finally.
I then ran test_basics.py, and after fulfilling a ton of other
dependencies, I finally only had one failing test left:
test_all_periodic_no_boundary. The complete log is attached at the
bottom, but essentially the failure is due to a mismatch in the number
of arguments on make_box (from meshpy). The 'missing' value is fixed to
None in the implementation of make_box. The following, simple patch
resolves the issue and lets the test pass for me:
diff --git a/hedge/mesh/generator.py b/hedge/mesh/generator.py
index e7fdfbe..51562aa 100644
--- a/hedge/mesh/generator.py
+++ b/hedge/mesh/generator.py
@@ -693,7 +693,7 @@ def make_box_mesh(a=(0,0,0),b=(1,1,1),
from meshpy.tet import MeshInfo, build
from meshpy.geometry import make_box
- points, facets, facet_markers = make_box(a, b)
+ points, facets, _, facet_markers = make_box(a, b)
mesh_info = MeshInfo()
mesh_info.set_points(points)
Frank Loeffler
Log:
$ python test_basics.py
======================================= test session starts ========================================
platform linux2 -- Python 2.6.6 -- pytest-1.3.3
test path 1: test_basics.py
test_basics.py ...................F..
============================================= FAILURES =============================================
__________________________________ test_all_periodic_no_boundary ___________________________________
def test_all_periodic_no_boundary():
"""Test that an all-periodic brick has no boundary."""
from hedge.mesh import TAG_ALL
from hedge.mesh.generator import make_box_mesh
> mesh = make_box_mesh(periodicity=(True,True,True))
test_basics.py:783:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a = (0, 0, 0), b = (1, 1, 1), max_volume = None, periodicity = (True, True, True)
boundary_tagger = <function <lambda> at 0x2073a28>, return_meshpy_mesh = False
def make_box_mesh(a=(0,0,0),b=(1,1,1),
max_volume=None, periodicity=None,
boundary_tagger=(lambda fvi, el, fn, all_v: []),
return_meshpy_mesh=False):
"""Return a mesh for a brick from the origin to `dimensions`.
*max_volume* specifies the maximum volume for each tetrahedron.
*periodicity* is either None, or a triple of bools, indicating
whether periodic BCs are to be applied along that axis.
See :func:`make_conformal_mesh` for the meaning of *boundary_tagger*.
A few stock boundary tags are provided for easy application
of boundary conditions, namely plus_[xyz] and minus_[xyz] tag
the appropriate faces of the brick.
"""
def count(iterable):
result = 0
for i in iterable:
result += 1
return result
from meshpy.tet import MeshInfo, build
from meshpy.geometry import make_box
> points, facets, facet_markers = make_box(a, b)
E ValueError: too many values to unpack
../../../hedge/lib/python2.6/site-packages/hedge-0.91-py2.6-linux-x86_64.egg/hedge/mesh/generator.py:696: ValueError
=============================== 1 failed, 21 passed in 52.00 seconds ===============================
---------- Forwarded message ----------
From: Xueyu Zhu <zhucer2003(a)gmail.com>
Date: Fri, Apr 15, 2011 at 11:33 PM
Subject: Re: [Hedge] extract matrix information from hedge
To: Andreas Kloeckner <lists(a)informa.tiker.net>
Hi, Andreas
I revised the code with the analytical sol, maybe you can see if it is
ok.
best regards
zhu
On Fri, Apr 8, 2011 at 2:06 AM, Xueyu Zhu <zhucer2003(a)gmail.com> wrote:
>
>
> On Fri, Apr 8, 2011 at 1:55 AM, Andreas Kloeckner <lists(a)informa.tiker.net
> > wrote:
>
>> On Wed, 6 Apr 2011 16:07:35 -0400, Xueyu Zhu <zhucer2003(a)gmail.com>
>> wrote:
>> > Hi, Andreas
>> > after testing, the solution looks correct.
>>
>> I was expecting an actual test of convergence to a known solution, as
>> shown in test_elliptic in test/test_jit_discretization.py.
>>
>
> ok, I will revise it as soon as possible.
>
>
>>
>> > I put the my patch in the
>> > attachment for your reference. you can look at if that is the style for
>> you
>> > want. btw, how do you test your stable code in an automated fashion? I
>> > looked at test folder, but didn't get the clue. just putting this lines?
>> > how does it actually work?
>>
>> Documentation: http://pytest.org/
>>
>
> this is nice, thank you.
>
>>
>> All you have to do is functions named test_...() in the examples/ or
>> test/ folders. Those are then automatically found by pytest. There are a
>> few more subtleties that you can read about in the pytest documentation,
>> including what "mark_test" is all about.
>>
>> Andreas
>>
>>
>
On Thu, 14 Apr 2011 01:13:47 -0400, Saumil Patel <saumil.patel134(a)gmail.com> wrote:
> After I downloaded the two lbm.py files and tried running the code, it was
> giving me an error saying that I needed the numpy module.
I see. There shouldn't be a need to download the LBM things separately
if you get the 'staging' branch of hedge, where they're included. I hope
I mentioned that. If not, I apologize.
About numpy: You definitely do not want to compile that yourself. Just
use Ubuntu's package. (But you'll need the compilers anyway.)
> So I downloaded numpy. I assumed I didn't have an appropriate compiler,
> since I was getting errors from the numpy setup.py file. Before I started
> downloading compilers, I used the following website to begin the necessary
> steps for building packages (
> https://help.ubuntu.com/community/CompilingEasyHowTo). I am not sure if this
> is the most efficient way. I've done everything in Step 1. So, yes, I've
> used some 'sudo' lines.
Those are harmless, but also not necessary. :)
I figured you would follow these instructions here (which I've just
updated a bit):
http://wiki.tiker.net/Hedge/HowTo/InstallingFromGit/Ubuntu
> Another issue - I am also not sure how files need to be organized so that
> programs can work together (i.e. where should the NumPY package be saved if
> I need to use it in code). I've got numpy in a "download" folder while
> Python is a program application and it's files sit somewhere else.
Each Python interpreter has a global package directory, typically
somewhere in /usr/lib/python2.N/... That's where it'll search for
packages. In addition, there's virtualenv [1] (go read 'What it does' in
its docs), which we also use.
[1] http://www.virtualenv.org/en/latest/index.html
> I'll be sure to ask on the hedge mailing list next time. I'll try to do
> what I can before our meeting tomorrow. See you then.
See you, hope this helps,
Andreas