XMDS

出自Ubuntu中文


    1. ## should open with org-mode
      ##
  • 开始
    最困难的就是写xmds文件,要么写一个新的,或者就改写一下别人的文件。不过,并不意味着要从头写一个新文件,就像一般大家做得那样。所以,我们在这里介绍如何写这个东西。如果你不感兴趣,或者想快点,那就直接到第三章,学者如何修改一个代码文件。
    本章我们将写出xmds文件里面将要解析的关键字。并且实现一个简单的仿真代码。更完整的标签档案可以在11章找到。更高级的代码细节在后面介绍。
    **基本的仿真
    <?xml version="1.0"?>
    <!-- 上面的一行是xml文件都应该要使用的开头了,当然复杂的文件配置会有更 --
    -- 多的属性项目。这里只有是这样子了。本行作为一个注视项目;我们是使 --
    -- 用xml里面用来作注释的方式。 -->
    <!-- Example simulation: lorenz -->

<!-- $Id: lorenz.xmds 1526 2007-08-21 17:30:14Z paultcochrane $ -->
<!-- Copyright (C) 2000-2007 -->
<!-- Code contributed by Greg Collecutt, Joseph Hope and Paul Cochrane -->
<!-- This file is part of xmds. -->
<!-- -->
<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License -->
<!-- as published by the Free Software Foundation; either version 2 -->
<!-- of the License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the Free Software -->
<!-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, -->
<!-- MA 02110-1301, USA. -->

<!-- Adapted from the example in "Numerical methods for physics"-->
<!-- by Alejandro L. Garcia, pg 78-->

<!-- Try the simulation for different values of xo, yo and zo -->
<!-- e.g.: xo = 1, yo = 1, zo = 20 -->

<!-- Note: this simulation can be run as a shell/Perl/Python script by -->
<!-- changing the values of xo, yo and zo using the command line arguments -->

<simulation>
<!-- 上面的simulation项目是每个仿真必要的项目,表示了整个文件的根节
点,最基本的结构 -->
<name>lorenz</name>
<!-- 名字给出了主要的仿真名称,也是基本的结构。整个仿真的名称 -->
<author>Paul Cochrane</author>
<!-- 作者的名称,可以省略,但是做个纪念 -->
<description>
Lorenz attractor example simulation. Adapted from the example in
"Numerical methods for physics" by Alejandro L. Garcia, page 78.
</description>
<!-- 上面是描述,对于项目的描述一些介绍了。和最上面的一些注释相似。
可以写一些琐碎的东西 -->

<!-- Global system parameters and functionality -->
<!-- 全局参数、和函数的介绍 -->
<prop_dim>t</prop_dim>
<!-- prop_dim 指的是系统驱动的变量,传播的方向 -->
<stochastic>no</stochastic>
<!-- 是否随机**这个项目在最简项目里面没有。 -->

<!-- Global variables for the simulation -->
<!-- 仿真的全局变量,也就是一些方程中的常数项目 -->
<globals>
<![CDATA[
const double sigma = 10.0;
const double b = 8.0/3.0;
const double r = 28.0;
]]>
</globals>
<!-- 上面给出了一些基本的数值。另外,还有一些方程的边界值,本例中和
原来文档是不同的。下面的项目给出了边界值。 -->

<!-- Command line arguments -->
<!-- 命令行参数,这里给出了边界值 -->
<argv>
<arg>
<name>xo</name>
<type>double</type>
<default_value>1.0</default_value>
</arg>
<arg>
<name>yo</name>
<type>double</type>
<default_value>1.0</default_value>
</arg>
<arg>
<name>zo</name>
<type>double</type>
<default_value>1.0</default_value>
</arg>
</argv>
<!-- 上面通过参数结构给出了边界条件,也算是方程的不变结构,在原来文
档中的例子里面适合全局变量在一起的。作为全局常量的。 -->

<!-- Field to be integrated over -->
<!-- 下面给出了积分过程的一些描述项目,以field开头表示积分过程的描述。
其中samples是积分的每一个步骤采样。vector给出要计算的输出矢量。有名
字main,类型双精度,包含了三个变量x,y,z。以components来包含结构,
下面的常数值项目给输出变量了初始值。-->
<field>
<samples>1</samples>
<!-- sample项目,给出了是否在开始计算之前初始化,时候生成输出量,
比如均值和标准输出。 -->
<vector>
<name>main</name>
<type>double</type>
<components>x y z</components>
<!-- <filename format="ascii"> lorenzInput.dat </filename> -->
<![CDATA[
x = xo;
y = yo;
z = zo;
]]>
</vector>
</field>

<!-- The sequence of integrations to perform -->
<!-- 序列化,也就是开始进行数值积分过程。这里给出了这个过程的一些细节。
包括了要使用的算法algorithm、计算的区间interval、总的计算点数lattice,
每个计算节点间的采样的点数,以及数值积分过程的计算矢量。还是使用常值
列表给出。整个过程使用integrate节点给出。 -->
<sequence>
<integrate>
<algorithm>RK4EX</algorithm>
<!-- 这里算法包含了6种。RK4EX,RK4IP,ARK45EX,ARK45IP,SIEX,
SIIP,RK4EX是4阶详细状况下的龙格库塔,RK4IP是4阶******比较
乱,改天在补充这些东西 -->
<interval>15.0</interval>
<lattice>50000</lattice>
<samples>50</samples>
<vectors>main</vectors>
<![CDATA[
dx_dt = sigma*(y - x);
dy_dt = r*x - y - x*z;
dz_dt = x*y - b*z;
]]>
</integrate>
</sequence>

<!-- The output to generate -->
<!-- 输出部分。这里使用从标准输出给出计算的结果。group给出要输出的东
西,这里将输出三个变量。 -->
<output format="ascii" precision="double">
<group>
<sampling>
<!-- 这里定义了三个变量来描述输出结果。因为根据xmds的设计方法,
该部分的值都是要直接放到c程序里面的。-->
<moments>xOut yOut zOut</moments>
xOut = x;
yOut = y;
zOut = z;
</sampling>
</group>
</output>

</simulation>
<!--整个结果完成了,也就是根节点完成了。 -->


    • 完成计算
      完成了xmds的输入文件之后,我们接下来可以进行xmds的计算。输入命令如下:
      %xmds sample.xmds
      这样子,会由xmds一边生成代码,代码的名字与配置文件相同,结果为cc后缀的
      文件。同时,xmds调动gcc编译器生成可执行程序,并以配置文件名字相同。接
      下来我们运行程序就可以了,另外,我们可以进行cc程序的修改,也可以自己修
      改程序来完成我们的目标。
      另外通过xsil2graphics程序来生成几种程序的可应用的图形输出脚本。例子如
      下原来配置文件中所见。

接下来还有一个更复杂的例子。
**更复杂的仿真