示例#1
0
print('Importing Comsol API.')
from com.comsol.model.util import ModelUtil as client
print('Comsol API imported.')

print('Initializing stand-alone client.')
t0 = now()
client.initStandalone(False)
client.loadPreferences()
print(f'Client initialized after {now()-t0:.3f} seconds.')

if 'skip_load' not in sys.argv[1:]:
    print('Loading Comsol model.')
    t0 = now()
    tag = client.uniquetag('model')
    model = client.load(tag, 'blank.mph')
    print(f'Loading model took {now()-t0:.3f} seconds.')

# Possibly crash out of JVM.
if 'force_exit' in sys.argv[1:]:
    print('Exiting JVM.')
    jpype.java.lang.Runtime.getRuntime().exit(0)

# Calling `.halt(0)` would be even more forceful.
# Another thing I've tried to exit more gracefully, but to no avail:
#     from com import comsol
#     current_thread = jpype.java.lang.Thread.currentThread()
#     comsol.systemutils.SystemUtil.setMainThread(current_thread)
#     jpype.java.lang.Runtime.getRuntime().runFinalization()

# This won't be reached if "force_exit" is passed.
示例#2
0
文件: test_Linux.py 项目: ovevans/MPh
    print(f'    {folder}')
path = jpype.java.lang.System.getenv('LD_LIBRARY_PATH') or ''
print('System library search path is:')
for folder in path.split(os.pathsep):
    print(f'    {folder}')

print('Starting stand-alone Comsol client.')
from com.comsol.model.util import ModelUtil as client
client.initStandalone(False)
client.loadPreferences()

print('Testing if Comsol can load shared libraries.')
from com.comsol.nativejni import FlNativeUtil
FlNativeUtil.ensureLibIsLoaded()

print('Loading Comsol model.')
tag = client.uniquetag('model')
model = client.load(tag, '../tests/capacitor.mph')

print('Loading external image.')
tags = [str(tag) for tag in model.func().tags()]
names = [model.func(tag).label() for tag in tags]
tag = tags[names.index('test_function')]
model.func(tag).discardData()
model.func(tag).set('filename', '../tests/gaussian.tif')
model.func(tag).importData()

print('Solving model.')
for tag in model.study().tags():
    model.study(tag).run()