Tuesday, September 24, 2013



Deckelnik-Eliott unfitted scheme tests
 I tested the unfitted FE scheme from Deckelnik paper on a unit circle, solving 
$-\Delta u + u = f$
on unit circle,
& Neumann BC
for a known
$u = cos(\pi r^2)$

Here are my error convergence results:



It appears there is no problems with my implementation.

Thursday, September 19, 2013

Unfitted finite elements approach from Deckelnick / Eliott / Dziuk paper


imajna.oxfordjournals.org/cgi/reprint/drn049v1.pdf

This paper describes almost the same approach that we are using - obtaining solution on surface by extending to unfitted mesh containing h-narrow band around the surface.

Only difference seems that they are using orthogonal projection from earlier Dziuk's paper to extend the domain, and they do mention Greer's idea as well.

In essence, the unfitted mesh is restricted to a fitted mesh. Elements that fall across the boundary level sets are chopped to only the part inside the band. This creates problems when the restricted triangle comes out very small or narrow.














In the paper, diagonal preconditioning is used. Here are my convergence results with no preconditioning:

       

Monday, September 16, 2013

L2 convergence of restrictions to bands around surface

1. We expected the L2 error on Surface to level off with increasing width of band after a certain value. The following plot confirms this:

(The series represent meshes of edge sizes 0.002, 0.005, 0.01 restricted to bands of increasing width around the surface)
2. Next I refine the mesh and keep same strip width from above runs.
 
Conclusion:
While it is true that sufficient strip width (0.5) gives O(1/nodes) convergence [same as O(1/h^2)], it seems discouraging as we have to take quite a number of triangles that are not crossed by the surface. Figure below shows that the jagged boundary causes the method to behave worse than the case with simple square extension.  am currently looking for ways to improve this, as well as searching how did other people handle such problems.

Related papers I am looking at:

http://www.sciencedirect.com/science/article/pii/0898122185900586#

The problem is to solve a 2D elliptic equation with moving interface using a fixed unfitted mesh. Vertical derivatives of solution across the interface are prescribed.
 
Their approach is also to split the interface gradient into 2 components, one of which is given by oblique condition and the other component is added to the equation matrix. The ellipticity of the problem is proved.


Monday, February 4, 2013

Feb 1 2013 (Friday) meeting

1. Look at paper Chernyshenko - Non-degenerate Eulerian FEM for PDEs on surfaces
  • implement simple benchmark test cases for known problems
  • extend to parabolic equations (?)
  • Look at texture on surface as solution (steady equilibrium state) of parabolic PDE
  • Mean curvature flow (Find more references about it!)
    • Look at paper Greer-Improvement of Eulerian Method for PDE on general geometries
2. Look at vizualisation soft

Wednesday, March 14, 2012

SQL notes


Encountered this while trying to get a diff on two large (20k records, no indexes) tables:

SELECT * FROM Morningstar.dbo.MStar_CompanyInfo as A 
WHERE A.LocalName IS NOT NULL AND (A.ExchangeId+A.Symbol) NOT IN 
(SELECT (B.ExchangeId+B.Symbol) FROM Companies.dbo.MStar_CompanyInfo as B)

takes in 15 minutes :(. Seems like the natural way to do it, no?

However, from advice here,


SELECT (A.ExchangeId+A.Symbol) as NewData,(B.ExchangeId+B.Symbol) as OldData, A.* FROM Morningstar.dbo.MStar_CompanyInfo as A 
LEFT JOIN Companies.dbo.MStar_CompanyInfo as B
ON ((A.ExchangeId+A.Symbol)=(B.ExchangeId+B.Symbol))
WHERE (B.ExchangeId+B.Symbol) IS NULL AND A.LocalName is NOT NULL

returns same result instantly :D

Wednesday, August 17, 2011

Merge SQL tables

Existing system:
1. Download Xml data by Http request
2. SqlDataSet.ReadXml to load XML data into dataset
3. (Re)create empty Sql table based on the dataset schema - based on some code I found online
4. Use SqlBulkCopy to copy data from dataset into the new table

Table sizes are large... up to 200 columns, up to 10000 rows. Not manual by any means, and I'd say not even manually-scriptable since keeping track of 100 columns in script is pretty impossible.

Problem:
Several tables contain variations in Http request type that require me to get the table in pieces. So, I download 4 tables instead of 1, and they all have slightly different columns (Xml response omits NULL elements, and that causes some columns to be missing). Thankfully, I can rely that the columns with same data will always have same names. I need to UNION all rows from the 4 tables into 1 table adding nulls for missing columns, but Union does not work with missing columns. That means I need to JOIN all the columns first and then use Union. (Union works on rows, Join on columns). But when I try the full outer join or any other joins, I keep getting duplicate columns!! The internet is pretty full of Join/Union tutorials for a variety of problems, and it is frustrating to even try to read through all those search results. So far I haven't seen anything useful to me.

Let me formulate the problem with math maybe.
1. I want to find a 'universal' column space for all 4 tables - which is the set-union of their columns.
2. Place each of the 4 tables into this new space.
3. Once all tables are in common column space, it is easy to union them.

Solutions:
I'm sure there is some clever trick to join all columns together. But it is not obvious to me and thus useless.


- Suggested by Wenping, a coworker:
1. To find a common column space, I take the list of all columns from each of 4 tables. Since I know same columns will have same names, I can merge the lists, sort and remove all duplicates.
2. From this list I can create a SQL CREATE statement to make a new table
3. When I download tables, I can bulk copy them straight into the new common table or union into that table after downloading

- Before using SqlBulkCopy, check if the receiving table has all the columns in dataset. If not, I can use ALTER statement to add new columns and then bulk copy everything. This requires more coding work but will anticipate errors later on when suddenly new columns appear in the Xml response.

Thursday, June 30, 2011

SQL Bulk Copy with duplicate keys

Given:
- Large xml file containing entries that need to be in my database table. Some rows have same value for the table key (not necessarily completely duplicate rows!)
- SQL table, C# code

Problem:
Copy the entries from xml to SQL table. This is done fast using SQLBulkCopy function in .NET, but does not tolerate when input data has duplicate values for the primary key column. I really do not care about keeping the rows that are duplicate. Just throw them out so I can use the bulk copy for the 99% of the data.

Solutions.
Online blogs suggest a number of solutions:

- One is to create a temporary table with no duplicate entry constraints, bulk copy everything into that and then use SQL to copy temp table into the final table while maintaining constraints.

- Another way is to find all duplicate rows in a table in code, using hashtables.

- Next, using the Table.DefaultView.ToTable(distinct=true, columns), but this only removes duplicate rows, not  rows that have a certain column with duplicates.

- There is a way to do that with LINQ but I didn't even get to read that.

-------
I used a pretty short (imo) and fast way to do it using IEqualityComparer interface:

class RowEqualityComparer : IEqualityComparer
{
    public bool Equals(DataRow b1, DataRow b2)
    {
        return ((string)b1["Symbol"]) == ((string)b2["Symbol"]);
    }

    public int GetHashCode(DataRow b1)
    {
        // I'm not really sure what to do here or whether I should even worry
        return b1["Symbol"].GetHashCode();
    }
}

and then simply 

BulkCopy.WriteToServer(
           dst.Tables[table].AsEnumerable().Distinct(
               new RowEqualityComparer()).CopyToDataTable());

instead of 

sbc.WriteToServer(dst.Tables[table]);