Skip to content

Commit 531da62

Browse files
committed
2 parents 1bfb4ef + 882008c commit 531da62

14 files changed

+3771
-130
lines changed

src/ApplyOfflineMap.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "TempestRemapAPI.h"
2020
#include "OfflineMap.h"
2121
#include "netcdfcpp.h"
22+
#include "GridElements.h"
23+
#include "FiniteElementTools.h"
2224

2325
#include <fstream>
2426

@@ -273,14 +275,79 @@ try {
273275
AnnounceStartBlock("Applying first offline map to data");
274276
}
275277
*/
278+
279+
DataArray3D<int> dataGLLNodesIn;
280+
DataArray3D<double> dataGLLJacobianIn;
281+
282+
DataArray3D<int> dataGLLNodesOut;
283+
DataArray3D<double> dataGLLJacobianOut;
284+
285+
DataArray3D<int> * pdataGLLNodesIn = NULL;
286+
287+
DataArray3D<int> * pdataGLLNodesOut = NULL;
288+
289+
Mesh meshOverlap;
290+
Mesh meshSource;
291+
Mesh meshTarget;
292+
293+
Mesh * pmeshSource = NULL;
294+
Mesh * pmeshOverlap = NULL;
295+
296+
297+
if(optsApply.strInputMesh != ""){
298+
299+
//If the source mesh is finite volume, we need the source mesh for local p bounds preservation
300+
301+
meshSource.Read(optsApply.strInputMesh);
302+
meshSource.ConstructReverseNodeArray();
303+
meshSource.ConstructEdgeMap();
304+
pmeshSource = &meshSource;
305+
306+
307+
//If the source mesh is finite element, we need dataGLLNodes for local bounds preservation
308+
if(optsApply.fgll){
309+
310+
double dTotalAreaInput = meshSource.CalculateFaceAreas(optsApply.fContainsConcaveFaces);
311+
double dNumericalAreaIn = GenerateMetaData(meshSource,optsApply.nPin,false,dataGLLNodesIn,dataGLLJacobianIn);
312+
313+
pdataGLLNodesIn = &dataGLLNodesIn;
314+
315+
}
316+
317+
}
318+
319+
if(optsApply.strOverlapMesh != ""){
320+
321+
meshOverlap.Read(optsApply.strOverlapMesh);
322+
meshOverlap.RemoveZeroEdges();
323+
pmeshOverlap = &meshOverlap;
324+
325+
}
326+
327+
//If the target mesh is finite element, get dataGLLNodesOut
328+
if(optsApply.strOutputMesh != ""){
329+
330+
meshTarget.Read(optsApply.strOutputMesh);
331+
meshTarget.ConstructReverseNodeArray();
332+
meshTarget.ConstructEdgeMap();
333+
334+
double dTotalAreaOutput = meshTarget.CalculateFaceAreas(optsApply.fContainsConcaveFaces);
335+
double dNumericalAreaOut = GenerateMetaData(meshTarget,optsApply.nPout,false,dataGLLNodesOut,dataGLLJacobianOut);
336+
337+
pdataGLLNodesOut = &dataGLLNodesOut;
338+
339+
}
340+
276341
// OfflineMap
277342
AnnounceStartBlock("Loading offline map");
278343

279344
OfflineMap mapRemap;
280345
mapRemap.Read(strInputMap);
281346
mapRemap.SetFillValueOverrideDbl(optsApply.dFillValueOverride);
282347
mapRemap.SetFillValueOverride(static_cast<float>(optsApply.dFillValueOverride));
283-
mapRemap.SetEnforcementBounds(optsApply.strEnforceBounds);
348+
mapRemap.SetEnforcementBounds(optsApply.strEnforceBounds,pmeshSource,pmeshOverlap,pdataGLLNodesIn,
349+
pdataGLLNodesOut,optsApply.nPin);
350+
//mapRemap.SetEnforcementBounds(optsApply.strEnforceBounds);
284351

285352
AnnounceEndBlock("Done");
286353

src/ApplyOfflineMapExe.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ int main(int argc, char** argv) {
5656
//CommandLineString(strVariables2, "var2", "");
5757
CommandLineString(optsApply.strNColName, "ncol_name", "ncol");
5858
CommandLineString(optsApply.strEnforceBounds, "bounds", "");
59+
CommandLineString(optsApply.strInputMesh,"mesh_in","");
60+
CommandLineString(optsApply.strOutputMesh,"mesh_out","");
61+
CommandLineString(optsApply.strOverlapMesh,"mesh_ov","");
62+
CommandLineInt(optsApply.nPin, "in_np", 0);
63+
CommandLineInt(optsApply.nPout, "out_np", 0);
5964
CommandLineBool(optsApply.fOutputDouble, "out_double");
6065
CommandLineString(optsApply.strPreserveVariables, "preserve", "");
6166
CommandLineBool(optsApply.fPreserveAll, "preserveall");
6267
CommandLineDouble(optsApply.dFillValueOverride, "fillvalue", 0.0);
6368
CommandLineString(optsApply.strLogDir, "logdir", "");
69+
CommandLineBool(optsApply.fContainsConcaveFaces,"concave");
70+
CommandLineBool(optsApply.fgll,"gll");
6471

6572
ParseCommandLine(argc, argv);
6673
EndCommandLine(argv)

src/CoordTransforms.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,27 @@ inline void StereographicProjectionInv(
337337

338338
///////////////////////////////////////////////////////////////////////////////
339339

340+
inline void GnomonicProjection(
341+
double dLonRad0,
342+
double dLatRad0,
343+
double dLonRad,
344+
double dLatRad,
345+
double & dXs,
346+
double & dYs
347+
) {
348+
// Forward projection using equations (1)-(3)
349+
// https://mathworld.wolfram.com/GnomonicProjection.html
350+
351+
double dK = sin(dLatRad0) * sin(dLatRad) + cos(dLatRad0) * cos(dLatRad) * cos(dLonRad - dLonRad0);
352+
353+
dXs = cos(dLatRad) * sin(dLonRad - dLonRad0)/dK;
354+
355+
dYs = (cos(dLatRad0) * sin(dLatRad) - sin(dLatRad0) * cos(dLatRad) * cos(dLonRad - dLonRad0))/dK;
356+
357+
}
358+
359+
///////////////////////////////////////////////////////////////////////////////
360+
340361

341362
#endif // _COORDTRANSFORMS_H_
342363

0 commit comments

Comments
 (0)