Example #1
0
def test_setupRun():
    '''The run instances must have the same root as the original model.
    '''
    setupModelFile(modelPath)

    m = getModel()
    jobPath = os.path.join(testDir, 'testJob')
    m.addJob(jobPath, jobSequence=['geoGen'], numCoresPerJob=1)
    m.genGeomSweep('param1', [0.1, 0.2, 0.3])
    # TODO: agree to start counting with geo_0 even if we don't sweep
    m.saveModel()

    harn = qmt.Harness(modelPath)
    harn.setupRun()

    job0ModelPath = os.path.join(jobPath, 'geo_0', 'model.json')
    job2ModelPath = os.path.join(jobPath, 'geo_2', 'model.json')
    jm0 = qmt.Model(modelPath=job0ModelPath)
    jm2 = qmt.Model(modelPath=job2ModelPath)
    assert (jm0.modelDict['jobSettings']['rootPath'] == jobPath)
    assert (jm2.modelDict['jobSettings']['rootPath'] == jobPath)

    os.remove(modelPath)
    shutil.rmtree(os.path.join(jobPath, 'geo_0'))
    shutil.rmtree(os.path.join(jobPath, 'geo_1'))
    shutil.rmtree(os.path.join(jobPath, 'geo_2'))
    os.rmdir(jobPath)  # safety if jobPath == rootPath
Example #2
0
def test_runJob():
    '''Check results of run: here only geoGen (generated FreeCAD model files).
    '''
    setupModelFile(modelPath)

    m = getModel()
    jobPath = os.path.join(testDir, 'testJob')
    m.addJob(jobPath, jobSequence=['geoGen'], numCoresPerJob=1)
    m.genGeomSweep('d', [0.1, 0.2, 0.3])
    m.setPaths(freeCADPath=os.path.join(testDir, '..', 'examples', '1_3D_2DEG',
                                        '2DEGFCDoc.FCStd'))
    m.saveModel()

    harn = qmt.Harness(modelPath)
    harn.setupRun()
    harn.runJob()

    fc_job2 = os.path.join(jobPath, 'geo_2', 'freeCADModel.FCStd')
    myDoc2 = FreeCAD.newDocument('testDoc2')
    myDoc2.load(fc_job2)
    assert myDoc2.modelParams.d == 0.3

    # Check for illegal steps
    m.addJob(jobPath, jobSequence=['wrongStep'], numCoresPerJob=1)
    m.saveModel()
    harn = qmt.Harness(modelPath)
    harn.setupRun()
    with pytest.raises(ValueError) as err:
        harn.runJob()
    assert 'Job step is not defined' in str(err.value)

    os.remove(modelPath)
    shutil.rmtree(os.path.join(jobPath, 'geo_0'))
    shutil.rmtree(os.path.join(jobPath, 'geo_1'))
    shutil.rmtree(os.path.join(jobPath, 'geo_2'))
    os.rmdir(jobPath)  # safety if jobPath == rootPath
Example #3
0
    boundaryCondition={
        'voltage': 0.0})

# To perform a voltage sweep, we assign it to one of our geometry objects
# like so:
runModel.genPhysicsSweep(
    'tunnelGate', 'V', np.linspace(0.0, -1.0, 3), unit='V')

# Finalize the model:
runModel.setPaths(COMSOLExecPath=COMSOLExecPath,
                  COMSOLCompilePath=COMSOLCompilePath,
                  mpiPath=mpiPath,
                  pythonPath=pythonPath,
                  jdkPath=jdkPath,
                  freeCADPath=freeCADPath)

runModel.genComsolInfo(meshExport=None, fileName='comsolModel',
                       physics=['electrostatics'],
                       exportScalingVec=[0.5, 0.5, .5])

runModel.addJob(rootPath,
                jobSequence=['geoGen', 'comsolRun'],
                numParallelJobs=numParallelJobs,
                numCoresPerJob=4, comsolRunMode='debug')

# Save and execute the model:
runModel.saveModel()
jobHarness = qmt.Harness('model.json')
jobHarness.setupRun(genModelFiles=True)
jobHarness.runJob()
Example #4
0
# Finalize the model:
runModel.setPaths(
    COMSOLExecPath=COMSOLExecPath,
    COMSOLCompilePath=COMSOLCompilePath,
    mpiPath=mpiPath,
    pythonPath=pythonPath,
    jdkPath=jdkPath,
    freeCADPath=freeCADPath,
)

runModel.genComsolInfo(
    meshExport=None,
    fileName="comsolModel",
    physics=["electrostatics"],
    exportScalingVec=[0.5, 0.5, 0.5],
)

runModel.addJob(
    rootPath,
    jobSequence=["geoGen", "comsolRun"],
    numParallelJobs=numParallelJobs,
    numCoresPerJob=4,
    comsolRunMode="debug",
)

# Save and execute the model:
runModel.saveModel()
jobHarness = qmt.Harness("model.json")
jobHarness.setupRun(genModelFiles=True)
jobHarness.runJob()