from gmsh geo file to fenics mesh with subdomain and boundary facet exported

 

Posted in Programming, Research | Leave a comment

FreeCAD compatible Fenics mshr geometry building

Fenics geometry building API is based on CGAL, it can import CAD, but can not export CAD file like step. Here is a solution, not fully tested. This file may be further developed in github.

Continue reading

Posted in Uncategorized | Comments Off on FreeCAD compatible Fenics mshr geometry building

solved Fenics (2016.2) cpp code compiling error on ubuntu 16.04

for any expression in Expression for Fenics 2016.2( installed from PPA )

expr = """ x[2]> {} ? {}:{}""".format(disc_zmax, lambda_p, lambda_d)
print(expr)
K = Expression(expr, element=V.ufl_element()) # error in compiling

instant error log:


— The imported target “vtkRenderingPythonTkWidgets” references the file
“/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so”
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
“/usr/lib/cmake/vtk-6.2/VTKTargets.cmake”
but not all the files it references.

check if this file is missing or not
ls -l  /usr/lib/python2.7/dist-packages/vtk/libvtkRendering*
python-vtk6  (VTK6.2) is installed, and installed file list:

/usr/lib/python2.7/dist-packages/vtk/libvtkRenderingPythonTkWidgets.x86_64-linux-gnu.so


sudo ln -s /usr/lib/python2.7/dist-packages/vtk/libvtkRenderingPythonTkWidgets.x86_64-linux-gnu-6.2.so /usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so

#this is the only file needs symbolic link to /usr/lib/x86_64-linux-gnu/

then, error is solved

Posted in Programming | Comments Off on solved Fenics (2016.2) cpp code compiling error on ubuntu 16.04

Cmake cheatsheet

#Cmake cheat sheet in markdown

Continue reading

Posted in Uncategorized | Comments Off on Cmake cheatsheet

c and cpp pitfalls, mixing signed and unsigned integer, implicit conversion

1. mixing unsigned and sign int is a bad idea

  • first of all, remember: signed int types will be implicitly converted to unsigned if sizeof(signed int types) == sizeof(unsigned int types)
  • Google C++ coding standard, say “do not use unsigned integer”
  • C++ STL using size_t which is unsigned int to represent size of containters like std::vector, std::string
  • do not assume sizeof(int types), always #include <stdint.h> and use int64_t
  • compiler can warn warning: comparison between signed and unsigned integer expressions [-Wsign-compare] . However, mixed unsigned and signed int algorithm is not warned
  • JAVA before Java 8 SE does not support unsigned int, even in Java 8 SE you can not declare unsigned int types, but only using static methods, unsigned comparison.
    There are good reason not to supported it.
  • python built-in integer/long is unsigned, but ctypes module defined c++ unsigned types; python 3 integer will not overflow
  • see also

http://blog.robertelder.org/signed-or-unsigned-part-2/

example and explanation from stackoverflow

2. Relevant quote from the Standard: Expressions

10 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions, which are de?ned as follows:

2 clauses about equal types or types of equal sign omitted

  • Otherwise, if the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type shall be converted to the type of the operand with unsigned integer type.
  • Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, the operand with unsigned integer type shall be converted to the type of the operand with signed integer type.
  • Otherwise, both operands shall be converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

3. pitfall of overflow and underflow

  • overflow detection can not been done by compiler but user
  • float overflow could be captured and hook to abort routine
  • avoiding infinite looping for underflow by compiler warning

    comparison of unsigned expression >= 0 is always true [-Wtype-limits]

  • assigned minus int to unsigned int should be prohibited, try hex instead or UINT_MAX – 1, since compiler will not warn you for implicit conversion into unsigned int types

4. pitfall of implicit conversion

see more c and c++ pitfalls

Guru of the Week (GotW)

Guru of the Week (GotW) is a series of C++ programming problems created and written by Herb Sutter.

 

Posted in Programming | Comments Off on c and cpp pitfalls, mixing signed and unsigned integer, implicit conversion

compile c++ codes using Visual C++ Build Tools from the command prompt

Introducing the Visual Studio Build Tools

“If you have installed Microsoft Visual C++ Build Tools 2015 on Windows 10, open the Start menu and choose All apps. Scroll down and open the Visual C++ Build Tools folder. Choose Visual C++ 2015 x86 Native Tools Command Prompt to open the command prompt window.”

1) for single file source file

cl -> gcc , but the command options is different,

cl /EHsc hello.cpp

https://msdn.microsoft.com/en-us/library/f35ctcxw.aspx

2) for a small project, CMake is recommended,

it is handy to write one from example CMakeLists.txt online.

In your source code folder: md build && cd build && cmake ..

then using nmake instead of make

3) for exsitent vs solution using msbuild:

compile visual studio solution/project designed by VS IDE, no corresponding command on Linux.

search “MSBuild Command-Line Reference”

In the near future, other light weight IDE might support detecting “Visual Studio Build Tools”, e.g QtCreator

Posted in Programming | Comments Off on compile c++ codes using Visual C++ Build Tools from the command prompt

Mibox 2 install youtube and play to kodi (just as chromecast)

1. install shafa TV manager and/or ES file explorer to be enable install apk from USB/SD card
http://www.shafa.com/articles/yWNpNK6erhB6Q4dO.html

2. install Kodi/XMBC apk from shafa’s file manager (in toolbox) on USB storage

3. install apk of youtube for Google TV, and also enable USB keyboard in MiBox system setting -> Input.

3. enable DNLA, web http control, UPnP in kodi settings
http://kodi.wiki/view/web_interface
write down the IP (check on your router), port, user name and password on this setting page

For web http control, install the new “Chorus” theme addon

4. install “play to Kodi” Chrome extension, Firefox should be possible
then, right click to video link, kodi->play/queue
first of all, setup kodi extension to login to kodi web interface

5. disable screen saver, for Kodi

Posted in Uncategorized | Comments Off on Mibox 2 install youtube and play to kodi (just as chromecast)

Evaluation of OpenFOAM on bash on Ubuntu on windows 10

## installation

After Anniversary Build (2016 Aug) for x65 windows 10, it is possible to evaluate this beta feature in developer mode without upgrade to claimed unstable insider version.

see detailed tutorial:

To install ubuntu on windows 10 from power shell prompt:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

## overview
In addition to apt-get, some other tool are there like python2, and python3, gcc4.9, perl5. dbus, systemd
Xwindows has been explored by geeks, but it is not stable/usable to run GUI app.

After fireup bash, the current path is /mnt/c/Windwos/System32 . It is better to “cd /mnt/c//Documents/” at the end of .bashrc, not mess up system folder and for better locate file generated by bash commands.

## look around

dpkg -l to see installed package, while not sure snap pkg will be supported.
sudo apt-get update To update the repo, it will show trusty repo info
ls /dev/
ls /usr/include/, almost empty
lsb_release -a shows it is 14.04.4
uname -a
> Linux DESKTOP-DELL15 3.4.0+ #1 PREEMPT Thu Aug 1 17:06:05 CST 2013 x86_64 x86_64 x86_64 GNU/Linux

## test POSIX API

It may be used to easily run software previously POSIX only program on windows.
apt-get install gcc will install gcc 4.8 and *linux-libc-dev*

ls /usr/include/ will give unistd.h

## install OpenFOAM

see instruction:

two versions are available for ubuntu 14.04
openfoam30
openfoam4

OpenMPI may not work; ParaView is definetly not working.

apt-get install openfoam30, then apt-get remove openfoam30 (leave dependent pkg remained.)
install openfoam4 by force, will not install all paraview related tons of new packages.

apt-get download openfoam4
dpkg --force-all -i openfoam4

force remove this pkg can fix error message each time

## Run OpenFOAM solver


mkdir -p $FOAM_RUN
cp -r $FOAM_TUTORIALS $FOAM_RUN
cd $FOAM_RUN/tutorials

bash
/OpenFOAM/qingfeng-4.0/incompressible/simpleFoam/windAroundBuildings$ ./Allrun
Running surfaceFeatureExtract on /home/qingfeng/OpenFOAM/qingfeng-4.0/incompressible/simpleFoam/windAroundBuildings
Running blockMesh on /home/qingfeng/OpenFOAM/qingfeng-4.0/incompressible/simpleFoam/windAroundBuildings
Running snappyHexMesh on /home/qingfeng/OpenFOAM/qingfeng-4.0/incompressible/simpleFoam/windAroundBuildings
Running simpleFoam on /home/qingfeng/OpenFOAM/qingfeng-4.0/incompressible/simpleFoam/windAroundBuildings

## Feature wanted

– right click to open bash, just as cmd prompt, or git-bash

## upgrade to ubuntu 16.04
upgrade to ubuntu 16.04 is planned by official support


apt-get update
apt-get dist-upgrade
do-release-upgrade -f DistUpgradeViewNonInteractive -d

lxrun.exe is used to manage WSL. This command can be used to install or uninstall the Ubuntu image.

Posted in Uncategorized | Comments Off on Evaluation of OpenFOAM on bash on Ubuntu on windows 10

disable windows input method hotkey

UPDATE: it seems the following methods still fails, as restart pc or windows update will invalidated the setting

===========

Avoid the annoying hotkey to trigger the IME shape/punctation in Chinese for half/full
see tutorial: http://superuser.com/questions/327479/ctrl-space-always-toggles-chinese-ime-windows-7
In addition to disapble Ctrl-Space, IME shape/punctation hotkeys are also disabled, which are shift-space and ctrl-period respectively. Once your edit the hotkey in GUI, which you will fail, you may need to rerun this reg file again. Logout to make it take effect

copy the following into notepad and save as “diasableIMEHotkey.reg” to anywhere in your PC. right click “merge” will import them into registry.

[HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000010] for simplified Chinese,  for traditional Chiese, use : [HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000070]

Once your edit the hotkey in GUI, which you will fail, you may need to rerun this reg file again. Logout to make it take effect

Continue reading

Posted in Uncategorized | Comments Off on disable windows input method hotkey

Toshiba L650 laptop disassembling

QQ图片20160529094125
I got a 5 year old laptop, it does not boot, no screen show, no beeping. So I need to disassemble and check.
Generally, this laptop is easy to repalce harddisk or memory on the back.  And the dissabling is straight forwards.

Continue reading

Posted in Uncategorized | Comments Off on Toshiba L650 laptop disassembling

Introduction to Industrial IO (sensor framework for Linux)

introduciton to Industrial IO


  • overview of industrial IO. In short, SPI and I2C sensor framework for Linux
  • sensor categories: “ADC, DAC, light, accel(erometer), gyro, magnetometer, humidity, temperature, amplifier, frequency, orientation, health”, etc
  • merged to mainline kernel 3.14, used by beagleBone, sysfs and char device based, see the IIO architecture

related projects/libs


  • DAQmx base for linux: commercial lib from national instrument
  • comedi: PCI/PCIe, USB devices for data acquisition
  • hwmon: very low speed,traditionally for CPU temperature monitoring
  • HID: like mouse, keyboard, generally low speed input device
  • bluetooth smart:

user space IIO API


user space library libiio (https://wiki.analog.com/resources/tools-software/linux-software/libiio)

  • #include <iio.h> four basic classes: iio_contex, iio_device, iio_channel and iio_buffer
  • iio_trigger is kind of iio_device without channel but with name inc “trigger”
  • iio_context has internal operation functions structure, kernel driver
  • windows user can use libiio to access network iiod
  • python and cshaprt wrapping for user space API: python-iio libiio-cil-dev
  • XML context: attributes calibration data, scale, etc.

detailed

(http://events.linuxfoundation.org/sites/events/files/slides/lceu15_baluta.pdf) + scan_element(), iio_channel_is_scan_element(): elements in buffer is called scan /sys/bus/iio/devices/iio:devices/scan elements

  • read_raw() from register (possible 12bit) to integer in memory. NO integer to physical quantity (with unit) like comedilib?

trigger readings based on an external interrupt source hardware interrupt (IRQ pins) software interrupts (periodic timers, sysfs triggers)

design of IIO


  • modes: DIRECT,BUFFER SOFTWARE,BUFFER HARDWARE,BUFFER TRIGGERED
  • iio_triggered_buffer iio_events only found in kernel mode iio_core, see(linux/iio/triggered_buffer.h);trigger are software trigger, not hardware TTL signal in DAQ terminology?

documentation for IIO


source code


supported hardware list


About 200 device drivers by the time of kernel 4.4; many drivers supports a varierty of models.

see/search kernel source tree linux/iio, there are a few subfolders corresponds to sensor categories: “ADC, DAC, light, accel(erometer), gyro, magnetometer, humidity, temperature, amplifier, frequency, orientation, health”, etc

test of IIO dummy device on ubuntu 16.04


“dummy” a virtual sensor for testing

python-iio example

desired feature of IIO


  1. user space tool to expose sensors to webUI?
  2. devicetree: platform device support is supported such as beaglebone.
  3. standardisation calibration data in XML attribute file to simulate: IEEE 1451.4 Plug and Play Sensors (TEDS)
  4. possiblity of user space driver development based on user space SPI, i2c and libusb?
  5. physical value conversion “The functions comedi_to_physical, comedi_to_phys, comedi_from_physical and comedi_from_phys are used to convert between Comedi’s integer data and floating point numbers corresponding to physical values (voltages, etc.). ”
Posted in Linux, Sensor | Comments Off on Introduction to Industrial IO (sensor framework for Linux)

A recommendation for free of charge 2D CAD and office system, also cross-platform

for office system, I recommend kingsoft  WPS office, which is based on Qt, much faster than java based solution. It has Android, Linux version in alpha, in addition to mature windows ‘s version

http://wps-community.org/download.html

For 2D CAD drawing, I recommend   Dassault system’ Draftsight,  it is  a professional level product. just need a email activation.  Linux version is still in beta.

http://www.3ds.com/products-services/draftsight-cad-software/free-download/

Both are not open source, but free of charge for production usage.

Posted in Linux | Comments Off on A recommendation for free of charge 2D CAD and office system, also cross-platform

Solve CFD via OpenFOAM in free CAx platform FreeCAD

Updated 2016-04-17

Boundary condition setup GUI has been done for preview

This is an early preview, only for people with experience of OpenFoam.
Test instruction could be found at
https://github.com/qingfengxia/FreeCAD/ … /Readme.md

I would love to see some feedback for stage III development, see roadmap:
https://github.com/qingfengxia/FreeCAD/ … roadmap.md

A video preview of OpenFoam plugin for FreeCAD Fem workbench
http://www.iesensor.com/FreeCADDoc/oepn … engXIA.mp4

The discussion of this module on FreeCAD community can be found here:

http://forum.freecadweb.org/viewtopic.php?f=18&t=13699

Continue reading

Posted in Linux, Programming, Research | Comments Off on Solve CFD via OpenFOAM in free CAx platform FreeCAD

Why power adapters for laptop are NOT compatible

see the word document contains figure to demonstrate various power adapters from diff manufacturers and how the claimed incompatible adapter could be reused.

why laptop power adapter are not compatible and howto

Posted in Uncategorized | Comments Off on Why power adapters for laptop are NOT compatible

Using paraview to visualise vorticity (Lambda2, vorticity, Q-Criterion)

Please download the word document, which contains the details on setting up the Python Calculator filter to calc lambda2, and use the advanced option of ‘Gradient’ filter to calculate vorticity, Q-Criterion.

Using Paraview to visualise vortex by lambda2

Posted in Programming, Research | Comments Off on Using paraview to visualise vorticity (Lambda2, vorticity, Q-Criterion)

What is the max array size you can declare (big data challenge)

by Qingfeng Xia @ iesensor.com 2015

With the popularity of BIG DATA concept, have you think about what is the max data structure you can run?http://stackoverflow.com/questions/216259/is-there-a-max-array-length-limit-in-c

Continue reading

Posted in Programming | Comments Off on What is the max array size you can declare (big data challenge)

Ten things you must do after install Openwrt 15.05 on raspberry pi B

This is not a tutorial, but list some interesting things for Openwrt

2015-09-14 by Qingfeng Xia
Continue reading

Posted in Ineternet of Things, Linux | Comments Off on Ten things you must do after install Openwrt 15.05 on raspberry pi B

Gmail backup to your google drive using app script (isenensor.com)

 

Link to my google spread sheet with script: Gmail backup isenensor.com

https://docs.google.com/spreadsheets/d/1vcQ-dJ_9iEmISLDnDjAFWrb4zcGOhEJzIJmMoq_MLYQ/pubhtml

Continue reading

Posted in Uncategorized | Comments Off on Gmail backup to your google drive using app script (isenensor.com)

Electronics under extreme environment (high temperature, low temperature)

Electronics under extreme environment

dirlist

 

 

 

 

Collection of public resource, product catalog, NASA presentation, etc

Posted in Uncategorized | Comments Off on Electronics under extreme environment (high temperature, low temperature)

smoother python 2.7 to 3.x transition (scite as IDE)

I aim to write code in python script, most of time, single file script, to run on both 2.x and 3.x with my favorite light-weighted IDE scite. So here is my setup
Continue reading

Posted in Programming | Comments Off on smoother python 2.7 to 3.x transition (scite as IDE)