Example al: Computed fields and data abstraction : heart model

Demonstrates the concepts of Computed fields. Shows how to create your own fields calculating quantities based on existing fields. The first image below shows the heart mesh with node glyphs illustrating the d/ds1 derivative at each node. The second image shows element point glyphs aligned with the fibre field, with the direction of the flattened arrows pointing in the fibre direction and the flattened sides oriented with the sheets. The second image also shows an iso-surface created using the coordinates defined to match the surface -x + y + z = 0.

Screenshot of example a/al


The comfile run by this example is as follows:

# Example_al: Computed fields and data abstraction : heart model
#
# You should by now be familiar with the concept of reading in exnode and exelem
# files containing definitions of fields and parameters for extracting their
# values at nodes and interpolating them over finite elements. These fields are
# referred to internally as FE_fields (FE=Finite Element), denoting that they
# are truly evaluated at nodes and elements.
#
# With Cmgui, you seldom deal with FE_fields directly because they are
# automatically made into a more abstract type of field called a Computed Field.
# The main advantage of Computed fields is that you can define your own as some
# calculation based on any existing fields. This frees you from having to
# needlessly calculate simple quantities in CM purely for export to CMGUI.
#
# At this time the following computed field types are available for your use:
#
# 2D_STRAIN = calculates the 4 values of the symmetric 2x2 finite/Green's strain
#     tensor from source undeformed and deformed coordinate and fibre fields;
# CLAMP_MAXIMUM = limit source field values to given maximums;
# CLAMP_MINIMUM = limit source field values to given minimums;
# CMISS_NUMBER = extract the CMISS number of the node or element as a field;
# COMPONENT = extract a component of a field as if it were a real scalar field;
# COMPOSITE = combine N scalar fields into a single vector field;
# CONSTANT = a vector of values remaining constant everywhere;
# CUBIC_TEXTURE_COORDINATES = normalized texture coordinates for the coordinates
#     projected back on to the nearest face of a cube at the origin;
# DEFAULT_COORDINATE = returns values of the first coordinate field defined over
#     the node or element, in rectangular Cartesian coordinates;
# DOT_PRODUCT = dot product of two vector fields with same number of components;
# EMBEDDED = for nodes with an element:xi (material coordinate) field defined
#     for them, evaluates the source field at that element position;
# FIBRE_AXES = from a field containing 1, 2 or 3 fibre angles and the coordinate
#     field, returns three vectors containing the fibre, sheet & normal vectors;
# FIBRE_SHEET_AXES = returns the FIBRE_AXES in order sheet, fibre, normal;
# FINITE_ELEMENT = wrapper for FE_fields - automatically made by CMGUI;
# GRADIENT = calculate the gradient of a scalar field using the derivatives of
#     the coordinate field;
# MAGNITUDE = square root of sum of squares of components of source field;
# NODE_VALUE = extracts a particular value/derivative/version for an FE_field
#     at a node;
# OFFSET = offset values of any source field by a vector of offsets;
# RC_COORDINATE = converts a source coordinate into rectangular cartesian;
# RC_VECTOR = converts source vector(s) into rectangular cartesian at the given
#     coordinate position;
# SAMPLE_TEXTURE = returns the intensity values from a source texture at the
#     position given by the source texture coordinate field. Texture flags
#     linear and nearest control whether values are interpolated between texels.
# SCALE = scale values of any source field by a vector of scale factors;
# SUM_COMPONENTS = scalar value of weighted sum of components of source field;
# XI_COORDINATES = returns the xi coordinates passed to the evaluate functions
#     as if they were a real field;
# XI_TEXTURE_COORDINATES = radiating from a given seed_element in the mesh, this
#     field makes texture coordinates that are continuous from elements to their
#     neighbours and always changing by 1 across each element. Works with
#     topologically rectangular meshes.
#
# The above list is by no means exhaustive. More functions are being added from
# week to week as required. If you require functions other than those listed
# above, especially if they are of general use to others, talk to us about
# having them added to the program. We are even looking into user-defined
# functions that are executed as commands in the UNIX shell, so even if your
# ideas seem a little customised for inclusion in the program, we may be able
# to support them in this manner.
#
#----------
#
# Set the default tessellation to use 4 segments in each element direction.
# This command does not exist on older versions of cmgui. It is safe to ignore errors.
gfx define tessellation default minimum_divisions "4" refinement_factors "1";

# Create a few materials in addition to the default for use later.
gfx create material copper ambient 1 0.2 0 diffuse 0.6 0.3 0 emission 0 0 0 specular 0.7 0.7 0.5 alpha 1 shininess 0.3
gfx create material gold ambient 1 0.4 0 diffuse 1 0.7 0 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.8
gfx create material heart ambient 0.3 0 0.3 diffuse 1 0 0 specular 0.5 0.5 0.5 shininess 0.5
gfx create material silver ambient 0.4 0.4 0.4 diffuse 0.7 0.7 0.7 emission 0 0 0 specular 0.7 0.7 0.7 alpha 1 shininess 0.6
gfx create material skin ambient 1 0.2 0 diffuse 0.8 0.7 0.45 emission 0 0 0 specular 0.4 0.2 0.2 alpha 1 shininess 0.2
gfx create material black_skin ambient 0.4 0.1 0.1 diffuse 0.4 0.2 0.1 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.2
gfx create material green ambient 0 0.4 0 diffuse 0 1 0.2 emission 0 0 0 specular 0.4 0.4 0.4 alpha 1 shininess 0.5
gfx create material purple ambient 0 0 0 diffuse 0.55 0.35 1 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.5
gfx create material blue ambient 0 0 0.5 diffuse 0 0.3 1 emission 0 0 0 specular 0.4 0.4 0.4 alpha 1 shininess 0.4
gfx create material trans_brown ambient 0.6 0.3 0.2 diffuse 0.6 0.3 0.2 emission 0 0 0 specular 0 0 0 alpha 0.3 shininess 0
#
# Make and draw axes of appropriate size for the heart model.
gfx modify g_element "/" general clear;
gfx modify g_element "/" point glyph axes_xyz general size "60*60*60" select_on material purple selected_material default;
#
# Read in the heart and display it upright in a CMGUI window, with endo-cardial
# surfaces shown in red.
gfx read nodes example heart.exnode
gfx read elements example heart.exelem
#
# Show lines:
gfx modify g_element heart lines coordinate coordinates material default;
#
gfx create window 1;
gfx modify window 1 image rotate 0 1 0 -90;
gfx modify g_element heart surfaces coordinate coordinates exterior face xi3_0 mat heart;
#
# List all the computed fields currently defined:
gfx list field;
# You will notice from the above list that 2 finite_element fields are defined,
# coordinates and fibres. List these two fields:
gfx list field coordinates;
gfx list field fibres;
# The coordinates field is in prolate spheroidal coordinates (lambda, mu, theta)
# while the fibres field returns three angles defined relative to lambda. The
# other two fields are xi and cmiss_number, as described earlier.
#
# The coordinate field is automatically converted to rectangular cartesian for
# the graphics; you may be interested to know that it is doing this by making
# a temporary RC_COORDINATE field to do this conversion for it. You can make
# this field yourself so that Cmgui does not have to make it with the following commands:
gfx define field rc_coordinates coordinate_system rectangular_cartesian coordinate_transformation field coordinates
# Let us have a look at this new field we have created:
gfx list field rc_coordinates
# This field has a rectangular cartesian coordinate system, which is how the
# rest of Cmgui interprets it, and the three components 1, 2 and 3 correspond to
# x, y and z. Since can now refer to the heart in rectangular cartesian
# coordinates, it is a simple manner, say, to get the plane -x + y + z = 0:
gfx define field plane sum_components field rc_coordinates weights -1 1 1
gfx modify g_element heart iso_surfaces coordinate coordinates iso_scalar plane iso_value 0 material silver
#
# If the coordinate system tells the rest of the program how the field values
# should be interpreted, you can imagine there are possibilities for, say,
# opening out the heart coordinates by lying that they are RC when in fact they
# are prolate. There is no particular field for this, but several fields can
# effect this change, for example, offsetting field values by 0:
gfx define field open_heart offset field coordinates offsets 0 0 0
gfx modify g_element heart general default_coordinate open_heart
# You may have to click "View All" on the graphics window to see the mesh now,
# since the 'focus' of the prolate coordinate system makes it somewhat larger
# than the RC space you are seeing now. A 'scale' field can be used to fix this:
gfx define field scale_open_heart scale field open_heart scale_factors 20 20 10
# To see this, choose it as the 'coordinate field' for the respective graphics
# in the scene editor.
# If you look at the commands for defining fields you will see that you can
# always choose the coordinate system of the field, and by default new fields
# are rectangular cartesian. As mentioned above, the coordinate system is a
# label saying what the field values mean, and is in no way a promise that the
# field will perform the conversion - only functions such as RC_COORDINATE and
# RC_VECTOR (see below) can promise this. In future we are likely to change the
# way coordinate systems are specified for fields since in many cases it does
# not make any sense to allow coordinate systems to change from source fields,
# and in the case of scalar fields the coordinate system is irrelevant. The
# NODE_VALUE field, in particular, requires that its coordinate systme matches
# that of its source FE_field.
# Now hide the iso_surfaces:
gfx modify g_element heart iso_surfaces coordinate coordinates iso_scalar plane iso_value 0 material silver invisible
#
# The 'fibres' field is special in that its values are not directly useful, and
# must be converted to fibre axes using the Jacobian of the coordinate field.
# In the following, we wish to orient small, flattened arrows with the fibre
# direction vector, while the flattened side shows the fibre sheet:
gfx define field fibre_axes fibre_axes coordinate coordinates fibre fibres
# (Try not to be confused by the frequent doubling of words in such commands -
# it is only because we use tokens appropriate to the type of field expected,
# and generally call the fields something similar!)
gfx modify g_element heart element_points coordinate coordinates use_elements glyph arrow_solid size "4*3*0.5" centre 0,0,0 orientation fibre_axes scale_factors "0*0*0" discretization "3*3*1" cell_centres material gold
# (The scale_factors are all zero in the above command because we don't want the
# glyphs to be scaled from their base 'size' by the 'orientation' field, which
# we know returns three unit vectors axes: the fibre direction, sheet direction
# and the normal to the sheet.) One point to note is that if you had specified
# 'orientation fibres' in the previous command, the result would be the same
# because Cmgui automatically wraps the fibres field in a fibre_axes wrapper to
# get the type of results it expects. Now let us hide these arrows:
gfx modify g_element heart element_points coordinate coordinates use_elements glyph arrow_solid size "4*3*0.5" centre 0,0,0 orientation fibre_axes scale_factors "0*0*0" discretization "3*3*1" cell_centres material gold invisible
#
# The NODE_VALUE field type is used to extract a particular value/derivative/
# version of an FE_field at a node as a vector with the same number of
# components as the source FE_field. You can then use this to orient and
# scale glyphs displayed at the nodes and thereby visualise derivatives and
# other values at the node. The following commands establish 4 of the 7
# derivatives defined at the heart nodes. Note that the prolate heart model only
# has derivatives for lambda; mu and theta vary linearly in prolate space (and
# hence represent curves). Cmgui will automatically wrap these prolate vectors
# with and RC_VECTOR wrapper, which ensures they are converted into rectangular
# cartesian vectors at their position in prolate space. Hence, lambda
# derivatives are aligned with the gradient of lambda.
gfx def field d_ds1 node_value fe_field coordinates d/ds1
gfx def field d_ds2 node_value fe_field coordinates d/ds2
gfx def field d_ds3 node_value fe_field coordinates d/ds3
gfx define field d2_ds1ds2 node_value fe_field coordinates d2/ds1ds2
gfx modify g_element heart node_points coordinate coordinates glyph arrow_solid size "0*2*2" orientation d_ds1 scale_factors "10*0*0" material skin
#
# Now open the scene editor, select the heart group, node_glyphs and try
# different derivatives for the orienation/scale field.
gfx edit scene
#
if (! $TESTING)
{
# To get a list of the commands and required parameters for creating your own
# computed fields, type:
  gfx define field ??
}
# Furthermore, once you have created several fields, you may wish to list all
# the fields you have created in the form of commands that can be used to
# recreate them, in the correct order so that any fields referred to by other
# fields are already defined. To do this type:
gfx list field commands
#
#----------
#
# Advanced uses of Computed field.
#
# 3-D plotting.
# You have already seen how choosing various default coordinate fields allows
# you to view your model in a different way. A powerful use of this is to
# define your own COMPOSITE fields made up of individual scalar fields and to
# use these as coordinates for graphics. For example, you could make up a
# composite field of Pressure-Temperature-Vapour Saturation and plot equally
# spaced (in xi) element_points over you mesh using this composite field as the
# coordinates. The result is a 3-D plot of these three [independent] quantities.
#
# Multi-component spectrums
# In a similar vein, you could choose the same composite field as the data field
# for any graphics and colour them with a multi-component spectrum, eg. showing
# green=Pressure, red=Temperature, blue=Vapour Saturation, and using additive
# colours at points where they are high in combination. A later example shows
# how to do this.
#

Files used by this example are:

Name            Modified     Size

example_al.com 17-Mar-2014 13k COPYRIGHT 17-Mar-2014 504 heart.exelem 17-Mar-2014 376k heart.exnode 17-Mar-2014 47k

Download the entire example:

Name                  Modified     Size

examples_a_al.tar.gz 09-Mar-2016 1.1M

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:14:00 20162
last breakTue Feb 24 03:14:00 20152
cmgui-wx-debugFailureSun Mar 6 00:14:33 20163
last breakTue Feb 24 03:12:00 20152
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:15:29 20162
last breakTue Feb 24 03:15:00 20153
cmgui-wx-debug-valgrindFailureSun Mar 6 01:09:05 201645
last breakSun Mar 6 01:08:00 201645
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:27 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debugFailureSun Mar 6 00:01:27 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:27 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-valgrindFailureSun Mar 6 00:03:23 20169
last breakSun Mar 6 00:03:00 20169
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:24 20167

Testing status by file:


Html last generated: Wed Mar 9 16:01:23 2016

Input last modified: Wed Mar 9 15:49:43 2016


CMISS Help / Examples / a / al