Comments (6)
Specifically, I would like to do something like this:
af = AnalyticalField(func=lambda x1,x2: 0.0-2*x1, fieldID=mp.DataID.FID_Temperature, unit=mp.U['K'])
mechanicalSolver.set(af)
mechanicalSolver.solveStep(mp.TimeStep(time=0,dt=.1,targetTime=1.,unit=mp.U.s))
f=mechanicalSolver.get(mp.DataID.FID_Displacement,time=1.*mp.Q.s)
f.plot2D(warpField=f, warpScale=5.e2)
from mupif.
I suggest to introduce FieldBase class to define spatial field abstract interface, consisting of getFieldID, getFieldIDName, getTime, evaluate and perhaps plot2D methods only. Then derive Field from FieldBase as representation of FEM based representation (need to keep the name to be compatible backwards). This would then allow straightforward implementation of other field representations, like AnalyticalField, also to be derived from FieldBase.
from mupif.
There is an issue about how to serialize the lambda (or other functor); some information here but also thinking about security implications; a lambda can contain e.g. os.system('rm -rf .')
or similar... Perhaps passing a string (python expression) with some predefined variables, such as xyz
(for spatial position) and time
; in that case, though, we can't make go beyond what one expression can contain. Security implications still remain, though.
from mupif.
There is something in bb814bb now, using numexpr, fast evaluator for string numerical expressions (see its docs for functions supported). Thus we have no security concerns (minimal virtual machine interprets the expression) and no serialization issues.
AnalyticalField
automatically defines local variables for the expressions (x
,y
,xy
for 2d, x
, y
, z
, xyz
for 3d), from what is passed to evaluate
, and evaluates the field in one go for all coordinates in the input data.
Example use here:
import mupif as mp
af=mp.field.AnalyticalField(dim=2,expr='sin(sqrt(x**2+y**2))',unit='m',fieldID=mp.DataID.FID_Porosity)
import numpy as np
X=np.arange(-5, 5, 0.25)
Y=np.arange(-5, 5, 0.25)
X,Y=np.meshgrid(X,Y)
Z=af.evaluate(np.dstack((X,Y)))
print(Z)
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(1,1,1,projection='3d')
ax.plot_surface(X,Y,Z,cmap='coolwarm')
plt.show()
EDIT: updated the example to match abfab4b
from mupif.
(As a TODO, perhaps assert that the evaluated value conforms to valueType
?)
from mupif.
A TODO for myself: mp.Field
(discretized) should also allow evaluation on an array of coordinates (a 3xN or 2xN np.array), not just on tuples or lists. mp.AnalyticalField
.
from mupif.
Related Issues (20)
- PyroFile & permissions HOT 8
- Wine64 CI broken (subprocess with PYTHONPATH in simplejobmanager) HOT 1
- unittest for crashing Model
- Pass workDirectory path to model __init__ HOT 1
- munin alarms HOT 1
- octree subdivides to tiny cells without limit, until recursion limit is reached HOT 1
- Octree localizer takes 10 minutes to fill for 155k-tetra mesh HOT 6
- tqdm progress bar should show chunks better HOT 1
- Safe termination of JobManager
- tools/ should be revived HOT 2
- Add Dumpable.preDumpHook
- support multiple schedulers
- Convert monitor to and other tools to mupif.monitor (exposed as JSON endpoint in the future) HOT 3
- MuPIF examples HOT 2
- remote logging HOT 1
- checkpointing in workflows
- Export fields to VTK HDF (as an alternative or simplification of .h5 + xdmf)
- temporal field (for both EDM and HeavyStruct) HOT 1
- Add VPN peer human-readable names to montiro API (with external JSON) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mupif.