-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Morpho-lang/fixes052
Improvements ready for 0.5.2
- Loading branch information
Showing
26 changed files
with
408 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
\hypertarget{meshgen}{% | ||
\section{Meshgen}\label{meshgen}} | ||
|
||
The \texttt{meshgen} module is used to create \texttt{Mesh} objects | ||
corresponding to a specified domain. It provides the \texttt{MeshGen} | ||
class to perform the meshing, which are created with the following | ||
arguments: | ||
|
||
\begin{lstlisting} | ||
MeshGen(domain, boundingbox) | ||
\end{lstlisting} | ||
|
||
Domains are specified by a scalar function that is positive in the | ||
region to be meshed and locally smooth. For example, to mesh the unit | ||
disk: | ||
|
||
\begin{lstlisting} | ||
var dom = fn (x) -(x[0]^2+x[1]^2-1) | ||
\end{lstlisting} | ||
|
||
A \texttt{MeshGen} object is then created and then used to build the | ||
\texttt{Mesh} like this: | ||
|
||
\begin{lstlisting} | ||
var mg = MeshGen(dom, [-1..1:0.2, -1..1:0.2]) | ||
var m = mg.build() | ||
\end{lstlisting} | ||
|
||
A bounding box for the mesh must be specified as a \texttt{List} of | ||
\texttt{Range} objects, one for each dimension. The increment on each | ||
\texttt{Range} gives an approximate scale for the size of elements | ||
generated. | ||
|
||
To facilitate convenient creation of domains, a \texttt{Domain} class is | ||
provided that provides set operations \texttt{union}, | ||
\texttt{intersection} and \texttt{difference}. | ||
|
||
\texttt{MeshGen} accepts a number of optional arguments: | ||
|
||
\begin{itemize} | ||
|
||
\item | ||
\texttt{weight} A scalar weight function that controls mesh density. | ||
\item | ||
\texttt{quiet} Set to \texttt{true} to suppress \texttt{MeshGen} | ||
output. | ||
\item | ||
\texttt{method} a list of options that controls the method used. | ||
\end{itemize} | ||
|
||
Some method choices that are available include: | ||
|
||
\begin{itemize} | ||
|
||
\item | ||
\texttt{"FixedStepSize"} Use a fixed step size in optimization. | ||
\item | ||
\texttt{"StartGrid"} Start from a regular grid of points (the | ||
default). | ||
\item | ||
\texttt{"StartRandom"} Start from a randomly generated collection of | ||
points. | ||
\end{itemize} | ||
|
||
There are also a number of properties of a \texttt{MeshGen} object that | ||
can be set prior to calling \texttt{build} to control the operation of | ||
the mesh generation: | ||
|
||
\begin{itemize} | ||
|
||
\item | ||
\texttt{stepsize}, \texttt{steplimit} Stepsize used internally by the | ||
\texttt{Optimizer} | ||
\item | ||
\texttt{fscale} an internal ``pressure'' | ||
\item | ||
\texttt{ttol} how far the vertices are allowed to move before | ||
retriangulation | ||
\item | ||
\texttt{etol} energy tolerance for optimization problem | ||
\end{itemize} | ||
|
||
\texttt{MeshGen} picks default values that cover a reasonable range of | ||
uses. | ||
|
||
\hypertarget{domain}{% | ||
\section{Domain}\label{domain}} | ||
|
||
The \texttt{Domain} class is used to conveniently build a domain by | ||
composing simpler elements. | ||
|
||
Create a \texttt{Domain} from a scalar function that is positive in the | ||
region of interest: | ||
|
||
\begin{lstlisting} | ||
var dom = Domain(fn (x) -(x[0]^2+x[1]^2-1)) | ||
\end{lstlisting} | ||
|
||
You can pass it to \texttt{MeshGen} to specify the region to mesh: | ||
|
||
\begin{lstlisting} | ||
var mg = MeshGen(dom, [-1..1:0.2, -1..1:0.2]) | ||
\end{lstlisting} | ||
|
||
You can combine \texttt{Domain} objects using set operations | ||
\texttt{union}, \texttt{intersection} and \texttt{difference}: | ||
|
||
\begin{lstlisting} | ||
var a = CircularDomain(Matrix([-0.5,0]), 1) | ||
var b = CircularDomain(Matrix([0.5,0]), 1) | ||
var c = CircularDomain(Matrix([0,0]), 0.3) | ||
var dom = a.union(b).difference(c) | ||
\end{lstlisting} | ||
|
||
\hypertarget{circulardomain}{% | ||
\section{CircularDomain}\label{circulardomain}} | ||
|
||
Conveniently constructs a \texttt{Domain} object correspondiong to a | ||
disk. Requires the position of the center and a radius as arguments. | ||
|
||
Create a domain corresponding to the unit disk: | ||
|
||
\begin{lstlisting} | ||
var c = CircularDomain([0,0], 1) | ||
\end{lstlisting} | ||
|
||
\hypertarget{halfspacedomain}{% | ||
\section{HalfSpaceDomain}\label{halfspacedomain}} | ||
|
||
Conveniently constructs a \texttt{Domain} object correspondiong to a | ||
half space defined by a plane at \texttt{x0} and a normal \texttt{n}: | ||
|
||
\begin{lstlisting} | ||
var hs = HalfSpaceDomain(x0, n) | ||
\end{lstlisting} | ||
|
||
Note \texttt{n} is an ``outward'' normal, so points into the | ||
\emph{excluded} region. | ||
|
||
Half space corresponding to the allowed region \texttt{x\textless{}0}: | ||
|
||
\begin{lstlisting} | ||
var hs = HalfSpaceDomain(Matrix([0,0,0]), Matrix([1,0,0])) | ||
\end{lstlisting} | ||
|
||
Note that \texttt{HalfSpaceDomain}s cannot be meshed directly as they | ||
correspond to an infinite region. They are useful, however, for | ||
combining with other domains. | ||
|
||
Create half a disk by cutting a \texttt{HalfSpaceDomain} from a | ||
\texttt{CircularDomain}: | ||
|
||
\begin{lstlisting} | ||
var c = CircularDomain([0,0], 1) | ||
var hs = HalfSpaceDomain(Matrix([0,0]), Matrix([-1,0])) | ||
var dom = c.difference(hs) | ||
var mg = MeshGen(dom, [-1..1:0.2, -1..1:0.2], quiet=false) | ||
var m = mg.build() | ||
\end{lstlisting} | ||
|
||
\hypertarget{mshgndim}{% | ||
\section{MshGnDim}\label{mshgndim}} | ||
|
||
The \texttt{MeshGen} module currently supports 2 and 3 dimensional | ||
meshes. Higher dimensional meshing will be available in a future | ||
release; please contact the developer if you are interested in this | ||
functionality. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
\hypertarget{vtk}{% | ||
\section{VTK}\label{vtk}} | ||
|
||
The vtk module contains classes to allow I/O of meshes and fields using | ||
the VTK Legacy Format. | ||
|
||
\hypertarget{vtkexporter}{% | ||
\section{VTKExporter}\label{vtkexporter}} | ||
|
||
This class can be used to export the field(s) and/or at a given state to | ||
a single .vtk file. To use it, import the \texttt{vtk} module: | ||
|
||
\begin{lstlisting} | ||
import vtk | ||
\end{lstlisting} | ||
|
||
Initialize the \texttt{VTKExporter} | ||
|
||
\begin{lstlisting} | ||
var vtkE = VTKExporter(obj) | ||
\end{lstlisting} | ||
|
||
where \texttt{obj} can either be | ||
|
||
\begin{itemize} | ||
|
||
\item | ||
A \texttt{Mesh} object: This prepares the Mesh for exporting. | ||
\item | ||
A \texttt{Field} object: This prepares both the Field and the Mesh | ||
associated with it for exporting. | ||
\end{itemize} | ||
|
||
Use the \texttt{export} method to export to a VTK file. | ||
|
||
\begin{lstlisting} | ||
vtkE.export("output.vtk") | ||
\end{lstlisting} | ||
|
||
Optionally, use the \texttt{addfield} method to add one or more fields | ||
before exporting: | ||
|
||
\begin{lstlisting} | ||
vtkE.addfield(f, fieldname="f") | ||
\end{lstlisting} | ||
|
||
where, | ||
|
||
\begin{itemize} | ||
|
||
\item | ||
\texttt{f} is the field object to be exported | ||
\item | ||
\texttt{fieldname} is an optional argument that assigns a name to the | ||
field in the VTK file. This name is required to be a character string | ||
without embedded whitespace. If not provided, the name would be either | ||
``scalars'' or ``vectors'' depending on the field type**. | ||
\end{itemize} | ||
|
||
** Note that this currently only supports scalar or vector (column | ||
matrix) fields that live on the vertices ( shape \texttt{{[}1,0,0{]}}). | ||
Support for tensorial fields and fields on cells coming soon. | ||
|
||
Minimal example: | ||
|
||
\begin{lstlisting} | ||
import vtk | ||
import meshtools | ||
|
||
var m1 = LineMesh(fn (t) [t,0,0], -1..1:2) | ||
|
||
var vtkE = VTKExporter(m1) // Export just the mesh | ||
|
||
vtkE.export("mesh.vtk") | ||
|
||
var f1 = Field(m1, fn(x,y,z) x) | ||
|
||
var g1 = Field(m1, fn(x,y,z) Matrix([x,2*x,3*x])) | ||
|
||
vtkE = VTKExporter(f1, fieldname="f") // Export fields | ||
|
||
vtkE.addfield(g1, fieldname="g") | ||
|
||
vtkE.export("data.vtk") | ||
\end{lstlisting} | ||
|
||
\hypertarget{vtkimporter}{% | ||
\section{VTKImporter}\label{vtkimporter}} | ||
|
||
This class can be used to import the field(s) and/or the mesh at a given | ||
state from a single .vtk file. To use it, import the \texttt{vtk} | ||
module: | ||
|
||
\begin{lstlisting} | ||
import vtk | ||
\end{lstlisting} | ||
|
||
Initialize the \texttt{VTKImporter} with the filename | ||
|
||
\begin{lstlisting} | ||
var vtkI = VTKImporter("output.vtk") | ||
\end{lstlisting} | ||
|
||
Use the \texttt{mesh} method to get the mesh: | ||
|
||
\begin{lstlisting} | ||
var mesh = vtkI.mesh() | ||
\end{lstlisting} | ||
|
||
Use the \texttt{field} method to get the field: | ||
|
||
\begin{lstlisting} | ||
var f = vtkI.field(fieldname) | ||
\end{lstlisting} | ||
|
||
Use the \texttt{fieldlist} method to get the list of the names of the | ||
fields contained in the file: | ||
|
||
\begin{lstlisting} | ||
print vtkI.fieldlist() | ||
\end{lstlisting} | ||
|
||
Use the \texttt{containsfield} method to check whether the file contains | ||
a field by a given \texttt{fieldname}: | ||
|
||
\begin{lstlisting} | ||
if (tkI.containsfield(fieldname)) { | ||
... | ||
} | ||
\end{lstlisting} | ||
|
||
where \texttt{fieldname} is the name assigned to the field in the .vtk | ||
file | ||
|
||
Minimal example: | ||
|
||
\begin{lstlisting} | ||
import vtk | ||
import meshtools | ||
|
||
var vtkI = VTKImporter("data.vtk") | ||
|
||
var m = vtkI.getmesh() | ||
|
||
var f = vtkI.getfield("f") | ||
|
||
var g = vtkI.getfield("g") | ||
\end{lstlisting} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.